Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Getting Rotation Angle for ArticulationBody

Discussion in 'Physics Previews' started by MetroRobots, Feb 28, 2022.

  1. MetroRobots

    MetroRobots

    Joined:
    Jan 11, 2022
    Posts:
    8
    Is there an easy way to calculate the rotation angle for a given ArticulationBody?

    The editor displays the transform's x rotation increasing between [-180, 180] (with y and z remaining 0)

    However, running the line
    Debug.Log(transform.localEulerAngles); 
    from a C# script results in different values, where the x value increases 0->90 (with y and z equal to 0), then decreases 90->0 (with y and z equal to 180).

    I acknowledge that these are equivalent euler angles, and that quaternions are the superior way to represent angles, however I've made this a Revolute Joint Type, intending for it to only move in one dimension, so it seems like there should be an easy way to get a single float value that represents the rotation angle.

    ToAngleAxis seems as though it may help, but it still flips back and forth between positive and negative axes.
     

    Attached Files:

  2. tjmaul

    tjmaul

    Joined:
    Aug 29, 2018
    Posts:
    467
  3. MetroRobots

    MetroRobots

    Joined:
    Jan 11, 2022
    Posts:
    8
    Works like a charm, thanks!
     
    tjmaul likes this.