Smooth Water

Blitz3D Forums/Blitz3D Programming/Smooth Water

wizzlefish(Posted 2005) [#1]
Hello,

I'm trying to make a plane of water move up, then back down, to simulate the waves. I'm not sure if this is how you would normally do it, but I decided it would be the easiest way, and it would still look OK. Here's the water updating code:Function MEDIA_UpdateWater()

If EntityY(water) <= 5
w_move# = 0.002
ElseIf EntityY(water) >= 5.15
w_move# = -0.002
EndIf

TranslateEntity water, 0, w_move#, 0

End Function[/code]

w_move# is initially set to 0. When the program is run, the water plane goes up and down, but it looks so uniform, and not very smooth and water-like. What should I do to fix this?

Thanks,
No Enemies


Ezbe(Posted 2005) [#2]
Check out CyberGoth's water-demo in the code archs:
http://www.blitzbasic.com/codearcs/codearcs.php?code=364


wizzlefish(Posted 2005) [#3]
Thanks...I'll be using this.


John J.(Posted 2005) [#4]
To make the water smoothly flow up and down, you should use a sinewave. The "sin" and "cos" functions are not only useful for triginometry, they have a very nice wave graph. You should probably do something like this:

Global wavecount

;...

While KeyHit(1)=0

;...

wavecount = wavecount + 5 ;change the 5 to whatever speed you want the water to wave
PositionEntity water, 0, Sin(wavecount) * .5, 0 ;Change the .5 to the height of the waves

;...

UpdateWorld
RenderWorld

;...

Wend



wizzlefish(Posted 2005) [#5]
Thanks...I'm going to have to mess around with it a bit, but I think I can make it work.