# 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.

## 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 on other sites
I believe you will find the information you need here:
http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html

##### 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.0ffloat 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.

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632948
• Total Posts
3009399
• ### Who's Online (See full list)

There are no registered users currently online

×