ScriptSpot

Forum topic · General Scripting

Getting object positions relative to another object's local space?

By jaijinsunrise · 2010-05-31

Description

UPDATE =================================

Thanks to Insanto and Anubis I have found two ways to do what I needed below!

1. theCoords = ($Box01.transform * (inverse $Plane01.transform)).pos
2. theCoords = in coordsys $Plane01 $Box01.pos

========================================

Hello, I'm having trouble getting object's positions relative to another object's rotation & position (transform). See example below:

 

I'm trying to get the coordinates of this box relative to this plane's local coordinates. The XYZ coords it should return in this case would be (0,-20,-25).

I have tried
in coordsys $Plane01 $Box01
 
but it returns the value of the Box's coordinates in world space.. something like (0, 3.536, 46.481)

I've managed to move the box in Plane01's world space using in coordsys $Plane01 move $Box01 [0,0,1] which is a tease but this is not what I need. Did I miss something here? I've looked all over in the documentation. I've included the example scene. Thanks for any help!

Comments (5)

Graph · 2010-06-01

(b.transform * (inverse p.transform)).pos

jaijinsunrise · 2010-06-01

Brilliant!! I think this method provides great insight as to how the position is calculated. Thank you so much!

Anubis · 2010-05-31

I dont see scene attached but with the next code I hope you will see what you miss ;)

--// scene setup...
p = plane width:60 length:60
b = box width:10 height:10 length:10
b.pos = [10,20,0]
b.parent = p
p.rotation.x_rotation += 22

--// test #1
b.pos -->> [10,18.5437,7.49213]
in coordsys p b.pos -->> [10,20,0]
--// Works OK

--// test #2
b.parent = undefined
b.pos -->> [10,18.5437,7.49213]
in coordsys p b.pos -->> [10,20,0]
--// Works OK

jaijinsunrise · 2010-06-01

Awesome, Thank YOU!!! Looks like I missed ".pos" when doing my tests(doh!). I knew this forum and members like you would help me see the light!. Thank you!

jaijinsunrise · 2010-05-31

I've created this hack, but I think it's a bit sloppy. There has to be a better way..

fn translatePosition theObject theTargetObject =
(
local helperDummy = dummy()
helperDummy.transform = theObject.transform
local lc = link_constraint()
helperDummy.controller = lc
lc.addTarget theTargetObject 1
local thePos = helperDummy.pos
delete helperDummy
return thePos
)

myPos = translatePosition $Box01 $Plane01