Simple buoyancy

BlitzMax Forums/BlitzMax Beginners Area/Simple buoyancy

EOF(Posted 2008) [#1]
What I want to achieve here is a simple buoyancy effect where the ball chases after the line but bobbles up and down a little before settling on the line
In the example code below the ball simply chases after the line (controlled by the mouse)


Any simple methods?
I tried using a Sin() method but things get jumpy/messy






Retimer(Posted 2008) [#2]
I think you could have it gain acceleration and only allow it to slow down by a certain rate per second, so it doesn't just smoothly decel to a stop point, but instead bounce up and down a bit as it keeps trying to reach its destination.


Warpy(Posted 2008) [#3]
I tried using a Sin() method but things get jumpy/messy

What do you mean by 'messy'?


EOF(Posted 2008) [#4]
Have another look at the code. I have added a black line to try and emphasize the problem



The ball should act as if it is connected to the line with a small spring. So, when the user moves around the ball plays catchup. Because it is connected by the spring it should bobble around a littel before settling

Currently though, the ball can sometimes look as if it is moving in sync with the line and thus the appearance looks "messy" and unrealistic


Warpy(Posted 2008) [#5]
Looks fine to me. Maybe it only looks wrong because it's the line you're moving and not the ball.

Of course your equation only works when the ball is under the water, so you need to take that into account.

I think you should start from first principles again and consider the forces involved.

There's a downward force due to gravity, acting on the whole ball, and an upward force due to upthrust, on the part of the ball that is underwater. For simplicity's sake, say that this force is directly proportional to the distance between the ball and the line, reaching a maximum when the distance is >= the radius of the ball.

So:
Fgrav# = mass*gravity
diff#=bally+ballradius-liney
If diff>2*ballradius diff=2*ballradius
if diff<0 diff=0
Fupthrust# = -diff*balldensity

yaccel# = (Fgrav + Fupthrust)
yspeed# :+ yaccel 'acceleration
yspeed:* .99 'friction
bally# :+yspeed 'movement



EOF(Posted 2008) [#6]
Mmm,
I think my 'buoyancy' term is misleading here
The effect I need would be to have the ball move around as if attached to springs. Like this:



So, in the picture above, if the black block was to suddengly fall down and hit the floor, the red ball would spring around a little before setttling

The part where my code looks wrong is in the situation where say, the red ball is 'springing' upwards at the same time as the black block gets pushed up