Page 1 of 1

How to use sim.setObjectParent and preserve the absolute position?

Posted: 15 Jan 2019, 21:44
by Uli_v
I noticed that using sim.setObjectParent is different than "moving" the object in the scene hierarchy to a different parent.

I.e. if I move an object that has a parent to the top level (root of the scene), then the position in the scene of this object (relative to "world") does not change. This is the behavior that I was hoping for.

But if I use the function sim.setObjectParent, then the position in the scene changes: E.g. I run the following code:

Code: Select all

    CuboidHandle=sim.getObjectHandle('Cuboid') -- Cuboid has a parent objects, that is not located at (0,0,0)
    sim.setObjectParent(CuboidHandle,-1,True) -- This "moves" the object in the scene
I noticed that the relative position to its parent is preserved if I use sim.setObjectParent, but if I use the GUI to drag the object to a new parent, then the absolute position is preserved.

I want to use sim.setObjectParent to change a parent, but preserve the absolute position in the scene.

The only solution I came up with is to store the absolute position of the object before changing the parent, then restore the absolute position. Is there a better way?

Thanks.

Re: How to use sim.setObjectParent and preserve the absolute position?

Posted: 16 Jan 2019, 00:33
by sjames
Hi,
You have an upper case 'T' in true. True is nil because it is undefined, so it is probably getting treated as false. So try:

Code: Select all

 CuboidHandle=sim.getObjectHandle('Cuboid') -- Cuboid has a parent objects, that is not located at (0,0,0)
 sim.setObjectParent(CuboidHandle,-1,true) -- This "moves" the object in the scene

Re: How to use sim.setObjectParent and preserve the absolute position?

Posted: 16 Jan 2019, 17:55
by Uli_v
Thank you, this solved the issue.