Author Topic: Aiming Algorithm  (Read 2560 times)

I'm trying to make an AI Player be dead accurate with it's aim

I have some "meh" code

function AIPlayer::predictPosition(%obj,%target)
{
   %sp=%obj.getMountedImage(0).Projectile.muzzleVelocity;
   %d=vectorDist(%obj.getMuzzleVector(0),%target.getEyePoint());
   %m=0.00012*%d+getRandom()*0.001;
   %pos=vectorAdd(%target.getEyePoint(),vectorScale(%target.getVelocity(),%sp*%m));
   %add=vectorScale(vectorCross(%obj.getEyeVector(),%obj.getUpVector()),-0.5);
   return vectorAdd(%pos,%add);
}

It works great...  for only the gun image and a few other items..

I'm looking for a more accurate version of this that works with any image, I know it exists, I just don't know where to look.
google and forum searches have not turned up anything helpful.


Try looking at fireHomingProjectile
I don't want it to home at the target.
I want my AIPlayers to aim their weapons at a predicted position and hit their target 90% of the time

I don't want it to home at the target.
I want my AIPlayers to aim their weapons at a predicted position and hit their target 90% of the time
The word 'homing' in this case is a misnomer
It does exactly what I think you want: the event fires a projectile, taking into account the players current velocity, and the projectile's gravitymod, so that it will exactly hit the player as long as their velocity doesn't change.

The word 'homing' in this case is a misnomer
It does exactly what I think you want: the event fires a projectile, taking into account the players current velocity, and the projectile's gravitymod, so that it will exactly hit the player as long as their velocity doesn't change.
:o

Try looking at fireHomingProjectile
mirror?

rtb is dead for me right now


already have it,

thanks
« Last Edit: October 02, 2013, 02:10:20 AM by MARBLE MAN »

Weren't the old bot events dead accurate?

Bots are/were dead accurate provided you were moving slowly or standing still.

It's impossible to be "dead accurate," unless you equip the bots with raycasting weapons. You can take a guess what their position will be at a future point in time, but if they change directions, jump, crouch, or stop after the projectile is fired it will go to the position you predict, not the position they're at.

"Homing" projectiles are one way around this, but they're very poorly implemented in Blockland. Essentially, every 100ms or so you delete the projectile and spawn a new one at the correct angle to hit the player.

This is untested, but it should predict the target's location based on their current velocity. Tested, works. This includes Z velocity, mind you, so if the player jumps gravity will forget it up.

Code: [Select]
function AIPlayer::predictiveAim(%this, %target, %player)
{
if(%player)
%targetPosition = %target.getEyePoint();
else
%targetPosition = %target.getPosition();
if(!isObject(%weapon = %this.getMountedImage(0)))
{
%this.setAimLocation(%targetPosition);
return %targetPosition;
}
%projectileSpeed = %weapon.projectile.muzzleVelocity;

%toTarget = vectorSub(%targetPosition, %this.getMuzzlePoint(0));

%dist = vectorDist(%this.getMuzzlePoint(0), %targetPosition);
%delta = %dist / %projectileSpeed;

%aimSpot = vectorAdd(%targetPosition, vectorScale(%target.getVelocity(), %delta));

%this.setAimLocation(vectorAdd(%aimSpot, vectorSub(%this.getEyePoint(), %this.getMuzzlePoint(0))));
return %aimSpot;
}
« Last Edit: October 02, 2013, 04:57:54 PM by $trinick »

It's impossible to be "dead accurate," unless you equip the bots with raycasting weapons. You can take a guess what their position will be at a future point in time, but if they change directions, jump, crouch, or stop after the projectile is fired it will go to the position you predict, not the position they're at.

"Homing" projectiles are one way around this, but they're very poorly implemented in Blockland. Essentially, every 100ms or so you delete the projectile and spawn a new one at the correct angle to hit the player.

This is untested, but it should predict the target's location based on their current velocity. Tested, works. This includes Z velocity, mind you, so if the player jumps gravity will forget it up.

Code: [Select]
function AIPlayer::predictiveAim(%this, %target, %player)
{
if(%player)
%targetPosition = %target.getEyePoint();
else
%targetPosition = %target.getPosition();
if(!isObject(%weapon = %this.getMountedImage(0)))
{
%this.setAimLocation(%targetPosition);
return %targetPosition;
}
%projectileSpeed = %weapon.projectile.muzzleVelocity;

%toTarget = vectorSub(%targetPosition, %this.getMuzzlePoint(0));

%dist = vectorDist(%this.getMuzzleVector(0), %targetPosition);
%delta = %dist / %projectileSpeed;

%aimSpot = vectorAdd(%targetPosition, vectorScale(%target.getVelocity(), %delta));

%this.setAimLocation(vectorAdd(%aimSpot, vectorSub(%this.getEyePoint(), %this.getMuzzlePoint(0))));
return %aimSpot;
}
Thank you, based god

Upon reviewing my code, I've noticed that I accidentally inserted a getMuzzleVector where I meant for a getMuzzlePoint. I have no idea why it worked, but I'm guessing it was circumstantial.

Upon reviewing my code, I've noticed that I accidentally inserted a getMuzzleVector where I meant for a getMuzzlePoint. I have no idea why it worked, but I'm guessing it was circumstantial.
Okay, thanks

Upon reviewing my code, I've noticed that I accidentally inserted a getMuzzleVector where I meant for a getMuzzlePoint. I have no idea why it worked, but I'm guessing it was circumstantial.
getMuzzleVector is very much similar to getMuzzlePoint

getMuzzleVector is very much similar to getMuzzlePoint
It returns the unit vector, not the location of the muzzle point. It shouldn't have worked at all, but whatever.