Jump to content
  • Advertisement
Sign in to follow this  

Angle+Speed question

This topic is 4147 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 all I am looking for a formula that will deteremine where an object will land given the initial angle and speed. I am writing a little game that has you enter the angle and speed of a cannon to see if you can hit an object far away from you. Thanks for any tips.

Share this post

Link to post
Share on other sites
Calculating an object's parabolic trajectory is a lot easier than you would think!

Gravity acts on all objects in flight, so first you have to establish a gravitational constant g that equals ~10m/s/s. (or, 10 m/s^2)

To find out where the cannonball will land, given elapsed time t and our gravitational constant g, we can solve for the vertical height of the round y:

y = v_iy * t + (0.5*g*t^2)

where v_iy is the initial vertical velocity of the round, computed by taking the sine of the angle fired at and multiplying it by the initial velocity. (maybe you can add a feature to the game where you can choose how much power to pack behind the shot, and use that for the value of v_iy!)

Horizontal distance is even easier. Given the initial velocity v and firing angle a:

x = v * cos(a);

Let's wrap it all up in an example.

#define G_CONST -10.0f

float power = 50.0f; // "power" is used as our initial velocity (Vi)
float a; // The angle the cannonball is fired at


void OnUpdate(float deltaTime)
cannonball.pos.x = power * cos(a); // Vx = Vi_x * cos(a)
cannonball.pos.y = (power * sin(a) * t) + (0.5f * G_CONST * t^2);


I hope this helps! If you have any questions, don't hesitate to ask.

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!