• Advertisement
Sign in to follow this  

how to find an intercept on a moving target

This topic is 1651 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);
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?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement