Hills in minigolf...

Discussion and feedback on Construct 2

Post » Mon Aug 18, 2014 4:56 pm

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?
Follow my CZero development on twitter https://twitter.com/CaptainZeroGame
B
57
S
15
G
5
Posts: 164
Reputation: 7,948

Post » Mon Aug 18, 2014 5:16 pm

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!!
Last edited by Colludium on Mon Aug 18, 2014 7:04 pm, edited 1 time in total.
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,183

Post » Mon Aug 18, 2014 5:19 pm

Interesting idea! You could quite easily turn a contour map into a series of friction zones and forces.
B
57
S
19
G
9
Posts: 639
Reputation: 9,533

Post » Mon Aug 18, 2014 6:12 pm

Colludium wrote: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".
B
36
S
8
G
8
Posts: 532
Reputation: 6,903

Post » Mon Aug 18, 2014 7:02 pm

@Fimbul,

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).
I only occasionally visit - I'm learning C# for Unity, but c2 is still a respectable game engine imo....
B
73
S
19
G
66
Posts: 2,198
Reputation: 42,183


Return to Construct 2 General