Archived

This topic is now archived and is closed to further replies.

CannonBall trajectory

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

I''d trying to implement a cannonball trajectory formula, but i''d only broke code... Having this... t.Gravity = -9.81f; t.InitalPosition = new Vector3(0,0,0); t.InitialDirection = new Vector3(0,.5,0); // PI/4 = 45 degrees t.Force = 10; // Impulse t.AirResistance = 7.2; // I don''t have idea why 7.2 I want to simulate a cannon ball, t.Force would be applied only when the cannon is shooted (Rigth?). How can i calcule the trajectory along the time? Any other parameter is missing? --- I''d played with this formula t.Gravity = -9.81f; t.InitialVelocity = 10; float X = t.InitialVelocity * (float)Math.Cos( Math.PI/4 ) * time; float Y = t.InitialVelocity * (float)Math.Sin( Math.PI/4 ) * time + (0.5f * t.Gravity) * time * time; t.trackPosition.X+= X + t.InitialPosition.X; t.trackPosition.Y+= Y + t.InitialPosition.Y; t.trackPosition.Z-= time + t.InitialPosition.Z;

Share this post


Link to post
Share on other sites
Haven''t checked if your ''code'' is accurate but one way of doing this would be to integrate with a euler backward formula, (which might be a bit overkill i guess) . You might also use a simpler integration method if you use dampening...

Your way could work aswell - you seem not to take the angles into account the right way...

Share this post


Link to post
Share on other sites
Air resistance would make your Position(time) function much more complicated. The part you''re playing with does not include Air resistance, so it should work fine (If i recall them physics formulas correctly)

Your angle Pi/4 is fixed, might as well make that a variable as well. Integration is only way i can think of to add air resistance to the thing.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You should also keep track of the velocity of the object


p.x = p.x + t * v.x
p.y = p.y + t*(v.y + 0.5 * gravity * t)

v.y = v.y + gravity * t


at the begining you set initial values for v.x, v.y p.x and p.y and that''s it.

Share this post


Link to post
Share on other sites