genetixsparkz

Members
  • Content count

    2
  • Joined

  • Last visited

Community Reputation

104 Neutral

About genetixsparkz

  • Rank
    Newbie
  1. how to find an intercept on a moving target

    Thanks!
  2. 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?