localPosition giving world coordinates
Closed, ResolvedPublic


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.


A is parented to B.

Start the game.

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

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.

Will Nielsen (k9crunch) 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"

Campbell Barton (campbellbarton) added a comment.Via Old WorldSep 3 2012, 3:42 AM

Moved from Blender 2.6 Bug Tracker to Game Engine

Dalai Felinto (dfelinto) added a comment.Via Old WorldSep 4 2012, 9:55 AM

confirmed the bug

Jerome Mahieux (littleneo) 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

@Campbell Barton (campbellbarton), @Dalai Felinto (dfelinto) @Mitchell Stokes (moguri)

for me this is not a bug as the parenting using world coordinates is the way that blender has to do parenting from long time ago (as described very well by @Jerome Mahieux (littleneo) including the initiation ritual :-)).

But, we have the following discrepancy: realtime parenting do the parenting in local coordinates.

Then, which is the path we have to follow? Add a new option in CTRL + P --> Set Parent to Object (local coordinates)?

Porteries Tristan (panzergame) closed this task as "Resolved".Via WebSun, Apr 3, 3:26 PM

As @Jerome Mahieux (littleneo) and @Jorge Bernal (lordloki) explain it's not bug, since there's 7 months without activity of the @Will Nielsen (k9crunch), i close the task.

Add Comment