Trying to reduce Rigidbody2D.AngularVelocty with AddTorque - Need to figure out how long it will take
So I'm making a 2D space game and trying to figure out rotation...
I have a fixed thruster speed and if the ship is clockwise from the desired angle: AddTorque(thrustSpeed) and if counterclockwise AddTorque(-thrustSpeed)
And this works but the ship yo-yos around the desired angle, so I need to figure ship angle + AngularVelocity (+ how long it will take to zero Angular Velocity) and that last part is where I'm having trouble.
I thought I could do AngularVelocity / thrusterSpeed, but with AddTorque it doesn't work out correctly.
I'm guessing the amount I pass to AddTorque is affected by the size and mass of the sprite, but I don't know how to use that.
So in short, what I want to do is tell the ship to rotate to angle 45 and it's rotation speed will increase (so it will turn) then start to decrease it's rotation speed so it won't overshoot angle 45.
Answer by FortisVenaliter · Jan 27, 2016 at 03:18 PM
So, you may be overthinking it a bit. What I usually do in this situation is limit the angular velocity by the angular distance. So, basically, as it approaches the target angle, it slows down it's rotation to 'fine tune'. You'll want to play with the values until it feels good, but a good place to start would be a maximum angular velocity of (2 x angular_difference) / second. At a wide angle, this won't limit the rotation speed at all, but as it gets closer, it will slow down.
FortisVenaliter, could you please share some code of your method?