Search Unity

controlling a ball using torque

Discussion in 'Scripting' started by Glowball123, Feb 27, 2021.

  1. Glowball123

    Glowball123

    Joined:
    Mar 10, 2016
    Posts:
    78
    what's the best way to control a ball using torque? and no, i dont want to set its angular velocity, i either want to add angular velocity or apple torque. the problem is when its difficult to have full 360 control over the movement because for example if i moved sideways and then wanted to move forward it would spin in the wrong direction. what is the best way to solve this?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,749
    I think it's quite doable. Remember torque is applied around an axis, so if I was facing a paper towel roll on the wall and pulled on it, I am applying a torque whose axis is an arrow to the left (if the roll is feeding off the top to me), or an arrow to the right (if the roll is feeding off the bottom).

    (NOTE: This distinction is created because Unity is a left-handed coordinate system. Look online for what that means but using your left hand thumb, index and palm you can see the x,y,z and curl.)

    Therefore, if you are looking down on a marble and want to apply torque forward, you are applying effectively some amount of either
    Vector3.right 
    if your camera always faces north, or else
    transform.right
    from your Camera (NOT THE BALL!) to cause that torque.

    Then if you wanted to torque it so it accelerates right, the torque vector is some magnitude of
    Vector3.back
    (or else
    -transform.forward
    of your Camera) to go right.

    Another note: For rolly-ball stuff in Unity, by default Rigidbodies cannot roll much faster than about one revolution per second unless you adjust this value upwards:

    https://docs.unity3d.com/ScriptReference/Rigidbody-maxAngularVelocity.html

    If you don't set that you'll be forever horribly sluggish and wonder what's going wrong. :)
     
    Last edited: Feb 27, 2021
    seejayjames and adamgolden like this.