Buoyancy

Blitz3D Forums/Blitz3D Beginners Area/Buoyancy

Terry B.(Posted 2007) [#1]
Alright so I've been working on this for a bit and decided its time to come on here.
Basically I have a cube, and a plane of "water", I want the cube to go underwater a little bit, come up, then go back under, in smaller and smaller amounts, untill finally it stops.
Like a boat in water, Im trying to make it buoyant.
So I got the Cube to bounce up and down, by simply applying, with some gravity.
If CUBEY#<WATERLEVEL
TranslateEntity CUBE,0,-(GRAVITY*DENSITY*CUBEVOLUME),0
endif 

That makes it bounce, but it never Stops.
So how would you go about making an object "Stop" bouncing eventaully?


xtremegamr(Posted 2007) [#2]
I'm not an expert on 3d programming, but I'm pretty sure that if you make a variable to keep track of the amount of times the cube bobs up and down, you should be able to stop it from bobbing after a certain amount of time. Like this:

-----------------------------------------------------------------------------
bob=5

if bob>=1 then
[insert bobbing code here]
bob=bob-1
end if


Terry B.(Posted 2007) [#3]
Thanks, thats what I thought too. But I was trying it earlier, no luck, I could get it to stop, but it wouldn't do it gradually and smoothly.


Stevie G(Posted 2007) [#4]
The cube should settle automatically - you just need to make sure that when in water it's upwards acceleration / force ( bouyancy ) is slightly higher than it's downwards acceleraton / force ( gravity ).

const TIMESTEP# = .005
const Gravity# = 9.8
global Bouyancy# = 10.2

[loop]

Acceleration = Acceleration - Gravity
If entityy( CUBE ) < WATERLEVEL
   Acceleration = Acceleration + Bouyancy
endif

translateentity CUBE, 0, Acceleration * TIMESTEP, 0

[loop]


Just vary the bouyancy factor to have objects surface quicker or slower etc..

Having it stop after a set amount of iterations won't look very good imo.

Stevie


D4NM4N(Posted 2007) [#5]
If CUBEY#<WATERLEVEL
TranslateEntity CUBE,0,-(GRAVITY*DENSITY*CUBEVOLUME),0
endif

You need something to reduce the bob, which is why it goes forever.

I would have done it something like:

'if entity is not in the water set:
     TimeFromfirstHit#=1.0

'else if entity is in the water,  for each loop/timeperiod set:
     TimeFromfirstHit#=TimeFromfirstHit#*0.8 '(the closer to 1.0 the slower to stop bobbing)
     if TimeFromfirstHit#<0.0001 TimeFromfirstHit#=0.0  '<-infinity catcher


TranslateEntity CUBE,0, -(GRAVITY*DENSITY*CUBEVOLUME)*TimeFromfirstHit#,0


Stevies way above looks good too.


jfk EO-11110(Posted 2007) [#6]
I would use sin/cos that is multiplied by a decreasing energy value "e". Additionally the sinus index "a" may increase/loop faster and faster (like in a rubber relaxing effect).
aspeed#=1.0
e#=2.0
while e>0.1
 a#=(a + aspeed) mod 359
 aspeed=aspeed*1.01
 e=e*0.975
 positionentity cube,0,sin(a)*e,0
 renderworld()
 flip
wend