Search Unity

What's the best way to rotate a rigidbody 360 degrees or more?

Discussion in 'Physics' started by fat_birb, Nov 9, 2019.

  1. fat_birb

    fat_birb

    Joined:
    Nov 9, 2019
    Posts:
    2
    I want to simulate robot servos in Unity. I thought things would work out easily using a HingeJoint, but I soon found out that the HingeJoint's JointSpring is limited to target positions between -180 and 180 degrees. What's more confusing is that if I set a JointSpring to move from 179 to -179 degrees, the spring moves 358 degrees, instead of only moving 2. I was thinking that I would just use a ConfigurableJoint, but I found out that the ConfigurableJoint has no property which gives the relative angle of the rigidbody from the joint. I have not yet implemented my own versions of rotating the joint and calculating the total degrees of rotation, as I'm wondering if there are any other ways of doing this. Plus, the physics engine may work in ways which I'm unaware of (for example, I do not know if it is valid to calculate the change in rotation based on angular velocity, as I do not know if the angular velocity changed between physics steps.)

    Any input will be appreciated!
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,779
    Do you need work with joints? Can you use IK?
     
  3. fat_birb

    fat_birb

    Joined:
    Nov 9, 2019
    Posts:
    2
    I believe joints would be the best option. I intend to make a physics based robot simulation; I'm not trying to animate a robot-esque character. I want to control each servo solely using forces, so that a script would need to implement a control loop which adds forces to keep the servo in position. I may try IK if absolutely nothing else works though.