Unity-Technologies / URDF-Importer

URDF importer
Apache License 2.0
232 stars 71 forks source link

How to manually change the transform of base link at runtime? #143

Closed 707346129 closed 2 years ago

707346129 commented 3 years ago

I want to change the position of the base link at runtime, but when I tried to set the value of transform.position of base link, it would go back to the original point at next frame. Is there any method to manually change the transform of base link at runtime?

peifeng-unity commented 3 years ago

Hi, this is the expected behaviour and the ArticulationBody component on the base link makes it not possible to manually change the transform by modifying the transform.position. To move the base link, you could try to use ArticulationBody.xDrive.target to drive the object with a force or teleport the base link via ArticulationBody.teleportRoot.

A-Ivan commented 3 years ago

@peifeng-unity, would another workaround to this be to have the robot as a child of another gameobject (i.e., an empty gameobject or a moving platform), and change the transform.position of that parent gameobject?

peifeng-unity commented 3 years ago

Ah, thanks @A-Ivan for reminding me! Yes, it would also work if the robot is a child of another game object. It would work with no problem if the moving platform also has articulation body component attached. Otherwise, the immovable flag needs to be unchecked on the base link articulation body so that the robot can move with the gameobject. However, the robot may fall in gravity if the configuration is not symmetric (e.g. a robot arm. It would not be a problem for a mobile robot). To connect the base link and the moving platform, you may also need to add configurable joint, which can anchor the base link on the platform.

at669 commented 2 years ago

Hi all, since the answer has been provided above, I will close out this issue. Please feel free to reopen if there is any follow-up.