any good way to move multiple shapes with regular API

Typically: "How do I... ", "How can I... " questions
Post Reply
Dusty
Posts: 5
Joined: 09 Jul 2018, 10:08

any good way to move multiple shapes with regular API

Post by Dusty »

Hi
Now I have a simple scene. A plane with multiple shapes on it. Now I'd like to move them all together but keeping them relative position relationship. Is there any simple way to do it with regular API?

fferri
Posts: 1217
Joined: 09 Sep 2013, 19:28

Re: any good way to move multiple shapes with regular API

Post by fferri »

Are the shapes static or dynamic?

How do you mean move them all together? Do you want to instantaneously change the position via API (e.g. sim.setObjectPosition)?

So you want to move a group of objects as if it is one object?

coppelia
Site Admin
Posts: 10366
Joined: 14 Dec 2012, 00:25

Re: any good way to move multiple shapes with regular API

Post by coppelia »

For simple shapes, dynamic or static, you could do something like:

Code: Select all

    sim.setThreadAutomaticSwitch(false) -- only needed if running inside of a threaded child script

    local dummy=sim.createDummy(0.01) -- created at the origin
    sim.setObjectParent(shape1Handle,dummy,true)
    sim.setObjectParent(shape2Handle,dummy,true)
    ...
    sim.setObjectParent(shapeNHandle,dummy,true)
    sim.setObjectPosition(dummy,-1,newPositionForDummy)
    sim.removeObject(dummy)
    
    sim.resetDynamicObject(shape1Handle) -- only needed if shapes are non-static
    sim.resetDynamicObject(shape2Handle) -- only needed if shapes are non-static
    ...
    sim.resetDynamicObject(shapeNHandle) -- only needed if shapes are non-static
    
    sim.setThreadAutomaticSwitch(true) -- only needed if running inside of a threaded child script
Cheers

Post Reply