0 Favourites

# Hills in minigolf...

• 5 posts
• What would be the best way to have hills in a top-down minigolf game using physics? I was thinking about an invisible sprite that just constantly applies a force in a certain direction to anything overlapping it. Is there some other way that would make more sense?

• To add onto your idea, I would use some maths so that the force on the ball will be at a maximum 1/2 way up the slope with no force on top and no force at the bottom of the slope (simulating a varying gradient). Something like:

Force = ForceFactorVariable * sin( 180 * distance(ball.x, ball.y, hill.x, hill.y) / (hill.width * 0.5) ) **

ForceFactorVariable could be the mass of the ball x some other factor to get it to look right or to allow you to change the height of the hill. I would also add a check to correct Force to zero if Force < 0 , just in case the combination of collision polygon and distance measurement cause a negative value to be returned (that could happen in a corner of a square hill sprite, for example).

Hope this makes sense....

**edited for some bad public maths!!

• Interesting idea! You could quite easily turn a contour map into a series of friction zones and forces.

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• Force = ForceFactorVariable * sin( 180 * hill.width * 0.5 / distance(ball.x, ball.y, hill.x, hill.y) )

You're in the right track, but there are a few caveats:

• This presumes the force gets stronger, linearly, the closer the ball is. What a weird hill! This is also likely to send the ball into the stratosphere if it crosses the middle (which would be even weirder if the hill had a tapered top).
• You need to take into account the steepness of the hill.

Personally, I'd just spread a bunch of invisible "force-applying" objects on the screen, creating a sort of "force map".

• Thanks for point out the poor logic and bad public maths on my part - the equation elements are the wrong way around!! That's what happens when you use your phone (poor excuse) for writing equations.

I've edited the original post and put the numerator and denominator the correct way around.

Edit: The idea with using sin is because sin(0) and sin(180) return zero - which should correspond to the top and bottom of the hill, whilst sin(90) which is the middle of the hill slope will return a 1 (max force factor value).

• 5 posts