Home

localPosition giving world coordinates
OpenPublic

Description

Category: Python

Object A is parented to object B.
Start the game engine and printing A.localPosition gives WORLD coordinates.

If you do realtime parenting in the game engine then localPosition will give you LOCAL coordinates.

So...

A is parented to B.

Start the game.

print( A.localPosition ) --> gives you A's WORLD coordinates

Do:
A.setParent( B ) ### A.setParent( A.parent) also works ###
print( B.localPosition ) --> Will then give you A's LOCAL coordinates



#####
Tested on official linux build 2.63 and on linux test build r49666

I tested localOrientation and localScale and they work correctly giving you local values without needing to reset the parent in realtime.

k9crunch (Will Nielsen) added a comment.Via Old WorldSep 3 2012, 12:53 AM
I made a typo:
"print( B.localPosition ) --> Will then give you A's LOCAL coordinates"
should be:
"print( A.localPosition ) --> Will then give you A's LOCAL coordinates"
campbellbarton (Campbell Barton) added a comment.Via Old WorldSep 3 2012, 3:42 AM
Moved from Blender 2.6 Bug Tracker to Game Engine
dfelinto (Dalai Felinto) added a comment.Via Old WorldSep 4 2012, 9:55 AM
confirmed the bug
littleneo (Jerome Mahieux) added a comment.Via Old WorldSep 28 2013, 8:37 PM
I don't think this is a bug, or if it is one, parenting in Blender must be modified.

Will you got this problem because you parented B to A with A in some other location (or with some other transformation) than the origin (than the identity matrix).
when you do this, you have then to :

. select B,
. shift S, 'cursor to selected' (= at B world position)
. alt-P, 'clear parent inverse'
. SHIFT S, 'selection to cursor' ( B goes back to position)

B local coordinates are now ok.

it's not intuitive at all I agree, and I don't see the need to keep world coord by default when altP

also, in the Blender ui the transform location of parented object displays world coodinates if you did not 'clear parent inverse' as below :
when you rotate or rescale A, the displayed coordinates are neither the world ones (not updated because parented) nor the local ones.
but B.matrix_local.decompose()[0] in bpy returns the right local location vector... so there's no match between the ui and the bpy.

for me either this ticket :

A/ should be closed, and Blender parenting process should be revised :
. 'clear parent inverse' by default when alt-P so we don't care about A position ....or A parents btw.....,
. keep the current way but as an alt-P option, like : 'parent it with world coordinates for some guru need'
-> bpy and ui info about local position will match,
-> bpy and bge newcomers don't need anymore to figure out what is the trick, which was really like an initiation ritual, something you earn because you search, work, and test a lot,
-> no need to check any of your bone-parented empties when there's a distance calculation bug in your game.................

if A, this ticket should be moved to the Blender tracker

B/ BGE retrieve the local matrix from the bpy B.matrix_local call
but this is still confusing since the info won't match between BGE/BPY and the ui

Add Comment