localPosition error or bug maybe?

I’m having a problem with setting the localPosition of an object in my game, using python, in blender 2.65a. Using “own.localPosition” seams to be acting the same way “own.worldPosition” would act. No matter what angle I have this object at it always moves along the worlds z axis, instead of the local z axis.

here’s the script I’m using (although I don’t believe this is the problem):

from bge import logic

scene = logic.getCurrentScene()
cont = logic.getCurrentController()
own = cont.owner

locZ = own ["locZ"]
dip = own ["dip"]
alive = own ["Alive"]

motionValue = 0.01

if alive == True:
    if locZ <= 0.0 and locZ > -0.01:
        dip = True
    elif locZ >= -0.1 and locZ <= -0.09:
        dip = False
    if locZ <= 0 and locZ > -0.1 and dip == True:
        locZ -= motionValue
        own.localPosition [2]-= motionValue
    elif locZ >= -0.1 and locZ < 0 and dip == False:
        locZ += motionValue
        own.localPosition[2] += motionValue
    own ["locZ"] = locZ
    own ["dip"] = dip

and an example blend with the problem: localPosition.blend (416 KB)

is anyone else having this issue? Any help would be really appreciated.:slight_smile:

localPosition is the object’s position relative to its parent and is the same as worldPosition when there is no parent. If you want to move the object along its local axes, create a movement vector, rotate it by the object orientation matrix, then add it to the objects position.

EDIT: Never mind, found it in the api, thanks for the help:)

Thanks for your response, I never noticed that before, anyways how do I rotate a vector by the orientation matrix?

Something like this.

import mathutils

# 1 unit on the z-axis
moveVec = mathutils.Vector([0, 0, 1])

# rotate vector

# apply movement
obj.worldPosition += move.Vec

otherwise you can use applyMovement((0,0,0),True) with True it move as you excpected for localPosition

(but is not immediate inside the script)