Playing a wave animation in BGE

If I make a wave with wave modifier then keyframe it making an animation, can I play it in the game engine with Logic bricks, or do I need a script. If there is an example to see that would be great.

digiman

Would need such a thing too, hopefully there will be some answers…

a quick test showed this doesnt work.

Is there a script for what I want?

digiman

thats a bit beyond me. if someone did figure this out, it would likely be very inefficient.

I believe shape keys might work, untested though

Let me tell you what I need and maybe there is a way to do it. I making an underwater scene and I wanted to see the water surface with the ocean bobbing up and down. Isn’t there a way to play animations in the game engine?

digiman

To my knowledge most modifiers simply get discarded when the BGE starts.
So you’d have to do this with code, but it’s not too difficult, there are several solutions on the forums ; )

I have looked that’s why I am asking. Let me know if there are any example blends.

digiman

try this maybe? it’s 3 years old though… so the code may be outdated :confused:

or try this - https://www.youtube.com/watch?v=o2nPTIeh2I8

I personally use WasserTextur to make animated normal maps for the bge, there is no physical displacement, but it gives the effect of moving/flowing water… but the software is only in german, and can be annoying to get the hang of using it… heres the link anyway (Website translated from german) - https://translate.google.co.uk/translate?hl=en&sl=de&u=http://www.blitzforum.de/showcase/%3Fproject%3D344&prev=search

I used to use normal maps with 2.49b but looking for something that behaves like an ocean wave modifier. Thanks for the suggestions

digiman

import bge

cont = bge.logic.getCurrentController()

own = cont.owner#Get owner

speed = 3#Set wave speed

height = 200#Set Wave Force

if “Vertex” not in own.attrDict:#Run Once

import random#Import Random


own.attrDict["Vertex"] = {}#Create Vertex Dict

mesh = own.meshes[0]#Get owner mesh

own.attrDict["Frame"] = 1#Create Frame Variable at frame 1


for i in range(mesh.getVertexArrayLength(0)):#For each vertex index
    
    vertex = mesh.getVertex(0, i)#Get vertex By index
    
    x = vertex.XYZ[0]#get Vertex X Coordinate
    
    y = vertex.XYZ[1]#get Vertex Y Coordinate
    
    frame = random.randint(100,300)/100.0#Get a random frame from 1.0 - 3.0
    
    if str([x, y]) not in own.attrDict["Vertex"]:#If Coordinate not in vertex library
        
        own.attrDict["Vertex"][str([x, y])] = [[vertex],frame, vertex.XYZ[2]]#Add Coordinate Vertex with random frame number, store vertex default height
        
    else:
        own.attrDict["Vertex"][str([x, y])][0].append(vertex)#Add secondary coordinate to vertrex list NOTE: There can be two vertex in exactly one point

for coor in own.attrDict[“Vertex”]:#For Corrdinate in vertex library

value = own.attrDict["Vertex"][str(coor)]#Create variable for ease of access

for vertex in value[0]:#For vertex in vertex list
    
    frame = value[1]#Get frame

    if frame  <= 2:#If frame is less than half of animation


        h = (frame **2 - 3*frame) + 2#Formula for parabolic coordinate plotting by frame num
    else:#Else
        frame = frame -1#Reset frame by half its animation
        
        h = -((frame **2 - 3*frame) + 2)#INVERTED Formula for parabolic coordinate plotting by frame num   
    h = h * height/100#Modify height of waves
    
    value[1] += speed/100#Add for the next frame by speed
    
    x = vertex.XYZ[0]#Get vertex X coor
    
    y = vertex.XYZ[1]#Get vertex Y coor
    
    new = [x, y, value[2] + h]#Store New coordinate for vertex relative to default height
    
    vertex.XYZ = new#Apply New coordinate for vertex

    if value[1] >= 3:#If end of frame
        
        value[1] = 1#Restart frame

import bge

cont = bge.logic.getCurrentController()

own = cont.owner#Get owner

speed = 3#Set wave speed

height = 200#Set Wave Force

if “Vertex” not in own.attrDict:#Run Once

import random#Import Random


own.attrDict["Vertex"] = {}#Create Vertex Dict

mesh = own.meshes[0]#Get owner mesh

own.attrDict["Frame"] = 1#Create Frame Variable at frame 1


for i in range(mesh.getVertexArrayLength(0)):#For each vertex index
    
    vertex = mesh.getVertex(0, i)#Get vertex By index
    
    x = vertex.XYZ[0]#get Vertex X Coordinate
    
    y = vertex.XYZ[1]#get Vertex Y Coordinate
    
    frame = random.randint(100,300)/100.0#Get a random frame from 1.0 - 3.0
    
    if str([x, y]) not in own.attrDict["Vertex"]:#If Coordinate not in vertex library
        
        own.attrDict["Vertex"][str([x, y])] = [[vertex],frame, vertex.XYZ[2]]#Add Coordinate Vertex with random frame number, store vertex default height
        
    else:
        own.attrDict["Vertex"][str([x, y])][0].append(vertex)#Add secondary coordinate to vertrex list NOTE: There can be two vertex in exactly one point

for coor in own.attrDict[“Vertex”]:#For Corrdinate in vertex library

value = own.attrDict["Vertex"][str(coor)]#Create variable for ease of access

for vertex in value[0]:#For vertex in vertex list
    
    frame = value[1]#Get frame

    if frame  <= 2:#If frame is less than half of animation


        h = (frame **2 - 3*frame) + 2#Formula for parabolic coordinate plotting by frame num
    else:#Else
        frame = frame -1#Reset frame by half its animation
        
        h = -((frame **2 - 3*frame) + 2)#INVERTED Formula for parabolic coordinate plotting by frame num   
    h = h * height/100#Modify height of waves
    
    value[1] += speed/100#Add for the next frame by speed
    
    x = vertex.XYZ[0]#Get vertex X coor
    
    y = vertex.XYZ[1]#Get vertex Y coor
    
    new = [x, y, value[2] + h]#Store New coordinate for vertex relative to default height
    
    vertex.XYZ = new#Apply New coordinate for vertex

    if value[1] >= 3:#If end of frame
        
        value[1] = 1#Restart frame