• Create Account

## how to find an intercept on a moving target

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1genetixsparkz  Members

104
Like
0Likes
Like

Posted 18 July 2013 - 12:17 PM

So here is my code roughly

Distance = Vector3.Distance(transform.position,Target.transform.position);
float timeToTarget;
float burnDistance = Projectile.MetersPerSecond * 2f * 2f * 0.5f;

if (Distance < burnDistance)
{
timeToTarget = Mathf.Sqrt(2 * Distance / Projectile.MetersPerSecond);
}
else
{
float velocity = Projectile.MetersPerSecond * 2;
TimeToTarget = 2 + (Distance - burnDistance) / velocity;
}
AimPoint = Target.transform.position + (Target.transform.rigidbody.velocity * TimeToTarget) + (Random.insideUnitSphere * Accuracy);
Distance = Vector3.Distance(transform.position,AimPoint);
TimeToTarget = Mathf.Sqrt(2 * Distance / Projectile.MetersPerSecond);

i'm trying to intercept a target with a projectile.

The issue is finding the proper time to target I think.

Basically when I find the distance to target then use that to find the time to target it changes my aimpoint to where the target will be in time seconds. But now the distance has changed. Now i'm now longer distance to target away i'm distance to aimpoint away from what i want to hit.

Basically as the target moves away from me it takes longer for the projectile to hit the aimpoint than is predicted by distance to target. So I can fix this somewhat by running the algorithm again. Only using the aimpoint as the target and getting a closer approximation. I solved this by looping the equation until i get to a certain tolerence but that seems very inefficient (it takes 3 to 5 loops to get close enough). Is there a better way?

### #2Álvaro  Members

20266
Like
2Likes
Like

Posted 18 July 2013 - 01:07 PM

Yes, there is a better way. This has come up many times. Here's a thread where I provide a solution: http://www.gamedev.net/topic/401165-target-prediction-system--target-leading/

### #3genetixsparkz  Members

104
Like
0Likes
Like

Posted 18 July 2013 - 01:58 PM

Thanks!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.