Jump to content
  • Advertisement
Sign in to follow this  
lorddanny

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 :D

Makes more sense now. Thanks again :D

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!