# C++ Physics on a ball

This topic is 2538 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
Every frame:

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

The same for every ball, mass does not affect it

##### Share on other sites
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

##### Share on other sites
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 ;)

##### Share on other sites

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

Makes more sense now. Thanks again

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633660
• Total Posts
3013221
×