# Waves terrain

Hello,
got a few questions regarding a “terrain” that should serve as ocean waves.
I got two terrains. One that uses a sinus calculation to generate simple sinus waves.
My question regarding that terrain is if it is possible to change the math so that it only plays one wave at a time?
Also how could I make the outer vertices not being influenced by the waves so that they lay flat?

My second terrain uses noise calculation for the waves.
The result is pretty nice but the terrain keeps flying slowly upwards.
Also at some point the cube falls through the ground…

Hope somebody could help me out. Thank you
Here is also a blend, just in case…ProceduralTerrain.blend (649.9 KB)

Not sure if you’ve determined the cause or not, but for the second wave, is the “slowly floating upwards” potentially caused by the line self.vertex.z = [etc] + self.timer.getElaspedTime(), would that part continuously increase? What happens if you remove the timer?

I don’t have much experience with python in blender, but my first thought is that the z value is constantly increasing with the timer. Best of luck if I’m way off base here.

just multiply the formula output by the inverse distance from the center `vertex.XYZ.xy.length`

You are right, if I remove the timer, the plane stays in its position.
The problem is that there won’t be any movement at all…

By adding the code you said, all the stays flat…

``````self.vertex.z = noise.multi_fractal(position*0.01, 1.0, 500, 8, 1) + self.timer.getElapsedTime()

self.vertex.z *= vertex.XYZ.xy.length
``````

Am I doing something wrong?

lol its a bit more complex than that, and you forgot the self in front of “vertex” (why do you even need that?)

`dist = vertex.XYZ.xy.length`
`z = ((maxdist-dist)*(dist<maxdist))/maxdist`

this is the simplest, `z` can be offset and multiplied to change the falloff.

im on mobile so i cant type code easily, or test it.

yeah that self. was redundant
sorry, but I don’t get it…
What do I do with z?
And where does that maxdist variable come from or is it a constant you assign?
Something like this?

``````            dist = vertex.XYZ.xy.length
vertex.z = ((10-dist)*(dist<10))/10
``````

This way it doesnt work, there is no movement

To have the vertices moving you must add the timer to the position.
Regarding the influence, you could use the vertex colors.

The code would be something like this:

``````timerVector = Vector((0.0, 0.0, self.timer.getElapsedTime()))
position = (self.object.worldTransform * (self.vertex.XYZ + timerVector))

self.vertex.z = noise.multi_fractal(position*0.01, 1.0, 500, 8, 1) * self.vertex.r
``````

With `self.vertex.r` you control the influence using the red component of the vertex color.

1 Like

Hello @a-k-m ! Sorry about my ignorance but what version of the game engine are you using?

I’m using upbge 0.2.5

You could just add a couple shape keys to your wave, keyframe them to make a wave animation, then add logic bricks to make it always play that animation on repeat.

does the wave have realtime collision detection with shape keys?

Yeah, I’m pretty sure it does as long as your settings are right to make animations use force. I was trying to make a boat game and got the waves to move the boat with shape key animations.

Hi thanks! I’m testing with UPBGE 0.3 Alpha and it is not working. I also tested inside UPBGEv0.2.5a-b2.79Linux64 and it’s not working.