Jump to content
  • Advertisement
Sign in to follow this  

Complex Lead Calculation

This topic is 5082 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

Hi, I've got this little piece of well known code for calculating lead on a target:
Vector2D LeadTarget( Vector2D sp, float bs, Vector2D tp, Vector2D tv )
	Vector2D D = tp - sp;
	float E = D.Dot( D );
	float F = 2 * tv.Dot( D );
	float G = bs * bs - tv.Dot( tv );
	float t = ( F + sqrt( F * F + 4 * G * E) ) / ( G * 2 );

	return D / t + tv;
This, quite naturally, only works for targets travelling in a straight line at constant velocity. What I would like to know is, how would you do it for targets on curved tragectories that also have acceleration?? (If it can be done without resorting to numerical methods). Cheers, arm

Share this post

Link to post
Share on other sites
Well, your lead calculation could actually be looked at as a first order Taylor approximation of the path of the target on the screen. All you have to do is add more terms (a t2 term, t3 term etc.) and evaluate it as you evaluate the first order approximation.

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!