Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Teleporting a Skinned Mesh Renderer that uses Hinge Joints

Discussion in 'Physics' started by sgoodrow, Jul 24, 2015.

  1. sgoodrow

    sgoodrow

    Joined:
    Sep 28, 2012
    Posts:
    150
    I have a skinned mesh renderer (rat) that has a few tail bones which have been connected together with hinge joints. In total there are 6 joints per rat. The joints allow the tail to react physically as the rat runs around and this works great!

    The rat can die, however, and I want to be able to reuse it in another part of the level when it does. So I try to move the rat (teleport) a long distance away but the hinge joint gets very messed up, like it doesn't respect the translation? I have tried setting the rigidbody isKinematic flag to true during the move but it doesn't seem to help.

    Is there some way to reset Hinge Joints or allow them to be moved in this fashion?
     
  2. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    897
    The best way to solve it is probably to place your rat inside an empty object and place everything in that objects local coordinates. Then you move the "empty" object, that way the hinge joint's coordinates will be preserved.
     
  3. sgoodrow

    sgoodrow

    Joined:
    Sep 28, 2012
    Posts:
    150
    Thanks for the insight PGJ! I don't fully understand though, so pardon my request for clarification. Here's my prefab setup:
    • rat_prefab (nav mesh agent, animator, other scripts)
      • rat_renderer (skinned mesh renderer)
      • rat_armature (skinned mesh renderer's bones)
        • various bones
        • more bones
        • some other bone
          • tail_bone_01
            • tail_bone_02
              • tail_bone_03
      • other stuff (hitboxes, trigger regions, etc)
    In order to get the joints to work properly, I have to unparent the tail bones to some non-moving parent. Currently I just unparent them to nothing.

    I think what you're suggesting is that I put the rat_prefab in another gameobject (call it rat_root for now), and don't move it. Re-parent the bones to that, and let the rat_prefab move around inside of it? So when it's time to teleport the rat, what would I move?

    If I'm understanding you correct, when I want to teleport the rat, I reset its local position to zero and move the rat_root to the new position?
     
  4. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    897
    You're more or less correct...

    Create an empty game object, this will be your "root" object and it will only have a transform - let's call it rat_roof. Place your prefab as a child of rat_roof. As you probably know, everything in a transform is relative to the parent object. In essence, children exist in a local coordinate system. Therefore, if you move rat_roof everything inside it will move along with it. But, the children will still retain their relative coordinates.

    When you want to move your rat_prefab, just move rat_root and once you want to teleport it, teleport rat_roof to the new position. That way every object, joint, and so on will
     
  5. sgoodrow

    sgoodrow

    Joined:
    Sep 28, 2012
    Posts:
    150
    Thanks PGJ, the translation of the hinge local coordinate parent is working great for moving the hinges to the new position.
     
    Last edited: Jul 27, 2015