I am playing around in the game engine and I am moving this cube around with this code:
import bge
from mathutils import Matrix, Euler
from math import radians
obj = bge.logic.getCurrentScene().objects["cube"]
property = bge.logic.getCurrentScene().objects["Empty"].get("movement")
move = 0.0
if property == 1: move = [1, 0.1]
elif property == 2: move = [1, -0.1]
elif property == 3: move = (obj.worldOrientation).to_euler(); move.rotate_axis("Z", radians(2.0))
elif property == 4: move = (obj.worldOrientation).to_euler(); move.rotate_axis("Z", radians(-2.0))
if move != 0.0 and property in (1, 2):
obj.localPosition[move[0]] += move[1]
elif move != 0.0:
print(move)
obj.worldOrientation = move
Where the property is just a int
representing which way to go or rotate. The movement is applied to the localPosition
so I would think that this would respect the rotation, but it doesn't and this is the result:
So how do I get it to always move in the local +- Y direction?