C++ Physics on a ball

Started by
3 comments, last by lorddanny 12 years, 3 months ago
Hi guys,

I'm trying to make a 3D cannon game which shoots balls out and hits targets. I have got the cannon to shoot balls out, but it only goes in a straight line. I wanted to add some physics to it so that the ball will fall to the ground and make a nice curve. How do I do that?

I have the following varibles:

Vector3 position
Vector3 velocity
Vector3 force
float mass

but I don't understand the maths behind it. Please help.
Advertisement
Every frame:


#define GRAVITY -0.01f
velocity.y += GRAVITY


The same for every ball, mass does not affect it
hmm... sorry, but I don't see how that would make the curve... For example, if the ball if launched or thrown from position 0, 0, 0, the y axis value should be positive at some point (or atleast from the start), but all I can work out from that (given gravity is -0.01) is all negative values.... so confused lol
You have to set your velocity to. for example:

pos(0,0,0)
velocity(0,1,0)

and in every update loop
velocity.y -= (0.01*time)

with this example you would throw your ball straight up and it will slow down until velocity.y < 0 then it will fall down again(don´t forget stopping it on the ground( = when pos.y == 0 again)

I hope you get it know ;)

You have to set your velocity to. for example:

pos(0,0,0)
velocity(0,1,0)

and in every update loop
velocity.y -= (0.01*time)

with this example you would throw your ball straight up and it will slow down until velocity.y < 0 then it will fall down again(don´t forget stopping it on the ground( = when pos.y == 0 again)

I hope you get it know ;)


Thanks :D

Makes more sense now. Thanks again :D

This topic is closed to new replies.

Advertisement