0
\$\begingroup\$

I am rotating my gameObject with the rotation of another gameObject - "hand" in its z-axis. The rotation of the object jumps to the current rotation of the hand and then it starts to rotate with the rotation of hand. I do not want this. What I want is that the object should start its rotation from its current rotation. For example, if hand starts its z rotation from 0 and the gameObject is currently at z = 50, it should start rotating from 50 and add the resulting rotation of the hand and not jump to 0. So that the rotation stays relative to itself. How do I achieve this?

    [Header ("Hand")]
    public GameObject targetHand;

    [Header ("3D Model")]
    public GameObject modelObject;

    public bool startRotating = false;

   void Update () {
          if(startRotating)
           Rotate ();         
    }
    void Rotate () {
        modelObject.transform.eulerAngles = new Vector3 (0, 0, targetHand.transform.eulerAngles.z);

        Vector3 myRotation = modelObject.transform.rotation.eulerAngles;
        myRotation.z = Mathf.Clamp (myRotation.z, 0, 90);
        modelObject.transform.rotation = Quaternion.Euler (myRotation);

    }
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.