Search Unity

Applying torque to different axis, independent of eachother

Discussion in 'Scripting' started by capnbishop, Dec 14, 2007.

  1. capnbishop

    capnbishop

    Joined:
    Oct 4, 2007
    Posts:
    50
    I want to be able to apply torque to an object among 3 axis in a manner so that they're applied independent of one another, and am having trouble figuring out exactly how.

    This object must roll and pitch to a certain degree (say, roll up to 90 degrees in either direction, and pitch up to 45 degrees in either direction), and yaw freely.

    The rolling and pitching is dampened and limited with a spring hinge, so that when rolling torque is applied, it will smoothly roll then slowly come to a stop when it hits the limit. The pitch is handled in the same manner. These should work along a local axis. Yaw, however, should work relative to the world axis.

    This isn't working out how I want it to. Suppose I apply torque so that the object pitches down. Then I apply torque so that it rolls to the right. What ends up happening is it will then yaw to the right. This is of course when the object is pitched down, rolling along the local axis is effectively a yaw along the world axis. Thus far it's set up as a set of hinge joints, connected one after the other, but that clearly isn't working as well as I had hoped.

    I want the torque I apply to roll the object to ONLY roll the object, the torque I apply to pitch the object to ONLY pitch the object, and the torque I apply to yaw the object to ONLY yaw the object; and all of these along a specific relative axis.

    I had come up with an idea to basically create a set of hinges for calculation purposes only, and apply roll torque to one, pitch torque to the other, etc., and copy and combine the resulting orientations to the visible object. This way I could apply rotations along each axis independently of one another. However, hard setting the transform like this means that I can't have it react to outside forces, like bumps against the wall which should cause it to roll or pitch slightly as it bounces off.

    Is there a better way of doing this?
    - John
     
  2. Foxxis

    Foxxis

    Joined:
    Jun 27, 2006
    Posts:
    1,108
    Rotations are a bit tricky, basically due to rotation ordering within the 3D system. I've had my fair share of problems with it, but been able to work around it.

    I can't really recommend a solution to your specific problem though, but I would suggest running some tests with basic rotations to figure out the best way to rig your system.
     
  3. capnbishop

    capnbishop

    Joined:
    Oct 4, 2007
    Posts:
    50
    Actually I managed to figure it out. I had a series of hinge joints, but was only applying rotation to the innermost object. The solution was to apply one type of rotation to that object, and then a different type of rotation to its anchoring rigidbody. That rigidbody was anchored to another rigidbody with another hinge. In the end, this all worked out quite well.
    - John