Jump to content
  • Advertisement
Sign in to follow this  
Math Max

Golf Ball Physics (involving 3D slopes)

This topic is 918 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 am making a Golf game in JMonkey 3 Engine. I am not using the physics of this engine because I want to do it myself. 


What I have at the moment:



Can shoot the ball over a terrain, collision detection with trees and walls ( with appropriate reactions ).


But now I am running into some trouble when trying to implement slopes/hills. (see picture)


When the ball is on the slope, I check whether it is going up ( then I decrease the velocity of the ball) or going down ( then I increase the velocity of the ball). Also if the ball is going uphill and it comes to a stop, I multiply the x and y velocity by -1 and i add some speed, so it comes back rolling again. But herein lies the problem. This only looks realistic when I shoot the ball straight up the hill, because only then does the ball roll down realistically ( because it rolls down the same path it went up). 


But ofcourse I want it also to work when I shoot the ball at an angle up the hill. I have done a lot of googling on this, but I can't really find an explanation anywhere. So I thought I'd ask it here.


Do you guys have any idea how to do this?


Share this post

Link to post
Share on other sites

I am not sure how in depth I should go with the answer. But what I would suggest is that you should be working with 3D vectors. The gravity would be a vector pointing down that gets added to the balls acceleration vector, if the ball is in the air. If the ball is on the surface you should modify the gravity vector with the surface normal by projecting and normalizing. You should look up a good vector tutorial. 

Edited by RedCarnage

Share this post

Link to post
Share on other sites
I'm with RedCarnage here, it sounds like you are dealing with the ball's velocity as a angle and magnitude. Your velocity should be a Vector3f

To slow down the ball you simply scale it by a damping factor

velocity = velocity.mult(Math.pow(dampingPerSecond, secondsSinceLastFrame));
To apply gravity on a slope
Vector3f slopeNormal; // A vector of length one pointing up, perpendicular to the slope face
Vector3f gravity; // the direction and strength of gravity
Vector3f slopeAcceleration = gravity.subtract(gravity.project(slopeNormal));
velocity = velocity.add(slopeAcceleration.mult(secondsSinceLastFrame));
If you need help calculating the slopeNormal let us know. Be sure to include the information you use to define a slope.

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!