I'm using BGE and I want to change the position of a face of a rigid body while the game is running. I don't know how to do it in Python. Thanks for your help!
1 Answer
This example moves the top face of the default cube in the default scene:
Note the print( dir ( some_obj ))
statements, this helps to examine the data structures:
import bge
import bpy
cont = bge.logic.getCurrentController( )
own = cont.owner
scn = bge.logic.getCurrentScene( )
obj = scn.objects["Cube"]
mesh = obj.meshes[0]
print( dir ( mesh ))
for i in range( 0, mesh.numPolygons ):
poly = mesh.getPolygon(i)
if i==1:
print("v1=%d v2=%d v3=%d v4=%d" % (poly.v1,poly.v2,poly.v3,poly.v4))
vert = mesh.getVertex(0, poly.v1)
print( dir (vert))
vert.XYZ = [vert.x+1.0, vert.y+1.0, vert.z+1.0]
vert = mesh.getVertex(0, poly.v2)
vert.XYZ = [vert.x+1.0, vert.y+1.0, vert.z+1.0]
vert = mesh.getVertex(0, poly.v3)
vert.XYZ = [vert.x+1.0, vert.y+1.0, vert.z+1.0]
vert = mesh.getVertex(0, poly.v4)
vert.XYZ = [vert.x+1.0, vert.y+1.0, vert.z+1.0]