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

Typically: "How do I... ", "How can I... " questions
Post Reply
Uli_v
Posts: 35
Joined: 14 Dec 2018, 18:07

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

Post 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.

sjames
Posts: 23
Joined: 23 Nov 2016, 18:53

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

Post 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

Uli_v
Posts: 35
Joined: 14 Dec 2018, 18:07

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

Post by Uli_v »

Thank you, this solved the issue.

Post Reply