Predicted target location
Posted
by
user3256944
on Game Development
See other posts from Game Development
or by user3256944
Published on 2014-06-12T20:37:01Z
Indexed on
2014/06/12
21:41 UTC
Read the original article
Hit count: 234
I'm having an issue with calculating the predicted linear angle a projectile needs to move in to intersect a moving enemy ship for my 2D game.
I've tried following the document here, but what I've have come up with is simply awful.
protected Vector2 GetPredictedPosition(float angleToEnemy, ShipCompartment origin, ShipCompartment target)
{
// Below obviously won't compile (document wants a Vector, not sure how to get that from a single float?)
Vector2 velocity = target.Thrust - 25f; // Closing velocity (25 is example projectile velocity)
Vector2 distance = target.Position - origin.Position; // Range to close
double time = distance.Length() / velocity.Length(); // Time
// Garbage code, doesn't compile, this method is incorrect
return target.Position + (target.Thrust * time);
}
I would be grateful if the community can help point out how this is done correctly.
© Game Development or respective owner