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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to rotate a rigidbody that has hinge?

Discussion in 'Scripting' started by khos, Sep 19, 2016.

  1. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,463
    Hi,

    Apologies if this is not the correct place to ask for some advice on this question, hopefully I could ask for your help with this:

    How to rotate a object with rigidbody and hinge?

    I have a gameobject with rigidbody and hinge(y axis pivot), on that a child also with rigidbody and hinge (other axis such as x), no forces are being applied to either e.g. via script.

    I have tried with this type of syntax:
    transform.RotateAround(...)
    transform.localEulerAngles = Vector3(....)
    rigidbody.rotation = Quaternion.LookRotation(...)
    Making animations on the transform....

    But these do not yet seem to have any effect.

    I read about rigidbody.MoveRotation, which should be used to rotate rigidbodies but soar can understand how to code this, I tried:
    var deltaRotation : Quaternion = Quaternion.Euler (new Vector3 (0, 20, 0));
    rigidbody.MoveRotation (transform.rotation * deltaRotation);

    Can I ask if this code looks to be correct to rotate this type of object on the y axis?
     
  2. IsGreen

    IsGreen

    Joined:
    Jan 17, 2014
    Posts:
    206
    Disable MeshRenderer and parent GameObject clone(no rigidbody, no hinge), and rotate or move it.
     
  3. khos

    khos

    Joined:
    May 10, 2016
    Posts:
    1,463
    Interesting idea, many thanks for that!