Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Configurable Joints - Setting targetrotation from current rotation

Discussion in 'Physics' started by Wagybwoi, May 5, 2021.

  1. Wagybwoi


    Sep 13, 2017
    I'm trying to figure out how to properly set target rotations for configurable joints.

    So far I've been having luck with using Quaternion.RotateTowards and plugging in the joint's current targetrotation and the end rotation to increment towards:

    joint.targetRotation = Quaternion.RotateTowards(joint.targetRotation, Quaternion.Euler(90f, 0f, 0f), 100f*Time.deltaTime);

    My issue is I'm getting weird results when trying to move the targetrotation from the current rotation of the joint to the end rotation. This is how I'm trying to execute it:

    Quaternion localRotation = Quaternion.Inverse(joint.connectedBody.transform.rotation) * joint.transform.rotation;
    joint.targetRotation = Quaternion.RotateTowards(localRotation, Quaternion.Euler(90f, 0f, 0f), 100f*Time.deltaTime);

    Any ideas what I'm doing wrong?
    Last edited: May 5, 2021