vertex sine-waving

hi all, i’m trying to move a single vertex along an axis through a sinusoidal path, but this lines i wrote seem not to work properly. any ideas?

thanx in advance.


import Rasterizer as R 
import GameLogic as GL 
import math 

scene = GL.getCurrentScene() 

obj = scene.objects['OBMyObj'] 
vert = obj.meshes[0].getVertex(0,5) 
vertCoords = vert.getXYZ() 

Couldn’t you just assign that vertex to a vertex group then use the wave modifier on that vertex group?

but… modifiers available in bge? argh i didn’t notice it!

but i still don’t know how to use them :smiley:

I dont see this as a sinosoidal curve… Since y and z ot the vertex do NOT change, it will result in ONLY oscilation on x of that vertex. Lets accept that your z will remain unchanged. Then, to reaching a sinosoidal curve along axis OX, you need to calculate the y coordinate on the basis of x. In that case, your sinosoidal curve will lye in a plane P parallel to XOY and displaced at z units off XOY…

Some calculation of the above may look like:

scale_factor = 100
co = vert.getXYZ()  # vertCoords
co.y = (math.sin(math.pi()*(co.x/180)))*scale_factor

The scale_factor gives you the height of the sinosoidal wave so above it is = 100.

The code above may need some further adjustments to the specific needs you may have.


hi abidos, thanx for your reply; in fact the movement i imagine is something like the “loading bar” in various software… imagine a vertex sliding from A to B along its X axis (not over a plane, in fact) and “smoothing” its movement near the two limits.

(beg my pardon for my ridiculous english)

apart from this, i tried your code and it didn’t work: it seems to that math.pi() isn’t correct and i used co[0], co[1] and co[2] to refer to vertex coords (i don’t know if it is correct!).

moreover, i have another problem: i don’t know how to execute the code ONLY at game start. i assume it’s something like activating false triggering with always actuator, but i cannot do it yet.

and last but not least i’d like to know something more about wave modifier in bge. atom, i’ll be glad if you can route me in the right direction.

i’ll take a peek into this forum, maybe tomorrow. thanx in advance for the help.

modifiers available in bge? argh i didn’t noticed it!

sorry, grammar error, you’re right :frowning:

by the way, in the meantime i did it with a shape action actuator. i’m still struggling to do it with python.

btw, the wave modifier doesn’t produce a real sinus.

yeah, i got it!

many thanx to all of you :slight_smile:

Well, really the math.pi shall be without the brackets… with the brackets is pi() in VBA… Sorry for that mistake… :stuck_out_tongue:

Other than that, I think the code is working… you just need to convert the argument to something which is a float. As getXYZ() is not my proc, I re-worked the code like this:

from Blender import *
import bpy
import math
def Sine_Test():
    sce =
    ob =
    me = ob.getData(mesh=1)
    vert = me.verts[0]
    scale_factor = 100
    for x in range(180):
        co =  # vertCoords
        co.y = (math.sin(math.pi*(1.0*x/180)))*scale_factor = co

With the default cube selected, you can actually see how it moves on sinosoidal pattern. Here is the testing blend file… To confirm the pattern is a part of a sine curve, I have taken out the results and put them in EXCEL to produce a simple graph… Here it is:

And I think, it is a half of a sine curve with amplitude = 100, right?? :wink:

BTW, is the ping-pong running on a sine curve? I thought it follows a ballistic curve which is far more difficult to calculate though…


What would it take to make this work on a plane, instead of a single vert? I’m not much of a python guy… at all.
trying fore this: