Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
Gamer With Dignity

Problems With My Guys' Aim

Recommended Posts

My guys aren't aiming right. Half the time they'll shoot 50 feet over doomman's head, the other half of the time they'll aim good. They're SUPPOSED to have perfect aim.

Map01 in Doom 2 is a great example of this. Stand on the ledge and they'll miss you by miles. Jump off the ledge and you get shot.

Bullet spawning code for my guys:

Script "SpawnEnemyBullet" (int hSpread, int vSpread) NET
{
	int enemyX = GetActorX(0);
	int enemyY = GetActorY(0);
	int enemyZ = GetActorZ(0);
	
	int spd = GetCVar("EnemyBulletSpeed")<<16;

	int uid = UniqueTID();
	int ang = (GetActorAngle(0))+(random(-hSpread,hSpread)<<8);
	SpawnProjectile(0, "PistolBullet", ang>>8, 0, 0, 0, uid);
	
	SetActivatorToTarget(0);
	int targetX = GetActorX(0);
	int targetY = GetActorY(0);
	int targetZ = GetActorZ(0)+10.0;
	int distX = enemyX-targetX;
	int distY = enemyY-targetY;
	int distV = enemyZ-targetZ;
	
	int distH = FixedSqrt(fixedAbs(FixedMul(distX,distX)+FixedMul(distY,distY)));
	int ptc = VectorAngle(distH, distV) % 1.0;
	
	SetActorPitch(uid, ptc);
	attachToPlayer(uid, 5.0, 0.0, -10.0);
	int velx = FixedMul(cos(ang), FixedMul(cos(ptc), spd));
        int vely = FixedMul(sin(ang), FixedMul(cos(ptc), spd));
        int velz = FixedMul(sin(ptc), -spd);
	SetActorVelocity(uid, velx, vely, velz, FALSE, FALSE);

	Thing_ChangeTID(uid, 0);
}
Download of my mod here:
https://mega.nz/#!v8oCSbhQ!CtU1ZKLF3kUn-_GQk12FNePY0WFPNZfRyPkP5NKSV-c

What am I doing wrong?

Share this post


Link to post
Gamer With Dignity said:

They're SUPPOSED to have perfect aim.

Then why do you have this:

Gamer With Dignity said:

int ang = (GetActorAngle(0))+(random(-hSpread,hSpread)<<8);

Unless the enemy has just called A_FaceTarget in its DECORATE, it's not guaranteed to look anywhere close to its target, anyway. To achieve perfect horizonzal aim, you'd have to calculate it similarly like you calculated the pitch.

Also, what does "attachToPlayer" do?

Share this post


Link to post
scifista42 said:

Then why do you have this:
Unless the enemy has just called A_FaceTarget in its DECORATE, it's not guaranteed to look anywhere close to its target, anyway. To achieve perfect horizonzal aim, you'd have to calculate it similarly like you calculated the pitch.


Nope, that line doesn't make a difference because the script is being called from within the actor's DECORATE and the hSpread and vSpread arguments are both passed as 0.

Also A_FaceTarget is being called before the script gets executed. Horizontal aim is fine, the only problem I'm having is with vertical aim.

Sometimes it's far above the player, other times it's below. The greater the difference is between the player and the enemy's z-value is, the more inaccurate it becomes.

I feel like there's an easy answer here, like it's a missing fixed point conversion or something, but I just can't see it.

scifista42 said:

Also, what does "attachToPlayer" do?


attachToPlayer is a function that positions spawned bullets relative to the player's view so that they appear to be coming out of the gun.

There's also an attachToEnemy function, but it's essentially the same thing with less calculations.

EDIT: Fixed it! :D

No idea what I did but I think it had something to do with setting activator out of order. I think bullets were spawning in at the player's z-level and not the enemy's.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×