Search Unity

Calling MovePosition/Rotation on nested RigidBodies does not work

Discussion in 'Physics' started by Prodigga, Dec 28, 2014.

  1. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Hey guys. I've noticed that I can't call MovePoistion/Rotation within the same FixedUpdate if the RB's are nested. For example,

    ParentGO.rigidbody.MovePosition(new Vector(1,0,0));
    childGO.rigidbody.MovePosition(new Vector(0,1,0));

    The result will be the parent moving by (1,0,0) but the child does not move. Same goes for MoveRotation. If I stop calling MovePosition on the parent, the child will start moving by (0,1,0). As soon as I call MovePosition on the parent again, the child will stop moving for as long as I call MovePosition or MoveRotation on the parent.
     
  2. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
  3. modegames

    modegames

    Joined:
    Dec 1, 2014
    Posts:
    37
    This same problem also happens with the MoveRotation method.

    There is no work around for this, or at least with a damn good go at this trying various things, I have not been able to find one :(
     
    Last edited: Feb 24, 2015
  4. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Yeah I think it is some sort of limitation?

    This sucks a fair bit. I was putting together some fairly generic platformer game scripts for my game. I had an elevator script that moved things up and down and another script called the Rotator script that spun things around. I could combine the 2 to have elevators that move up and down and spin around too. But this restriction means that it doesn't work.
     
  5. modegames

    modegames

    Joined:
    Dec 1, 2014
    Posts:
    37
    Yeah it's annoying but the restriction appears to be intentional it should be documented.

    You can work around this limitation though. We achieved this by duplicating the objects which had the rigid bodies and flattened them and removed the colliders and rigid bodies from the animated objects, then we added a script to the duplicated objects which have the rigid bodies but now not nested. Then on these objects we added a simple script which has a reference to the animated objects to then update the rigidbody with the transform of the animated object utilising the methods UpdatePosition and UpdateRotation.