I have numerous scripts for rotating a 2d object with analog stick, they all work but the rotation is not completely smooth. Its briefly unresponsive on NORTH, SOUTH, EAST, WEST, NORTH-EAST, NORTH-WEST, SOUTH-EAST and SOUTH-WEST. I have researched a lot and tried even more but nothing resolves this issue.
@hexagonius Could you please share how you resolved this issue. Thank you
By “Smooth” do you want an acceleration/deceleration effect, or just a constant speed effect? constant rotational speed from a to b is easy, but accel/decell is a bit tougher. I think Slerp works well to give the effect, but I’m not entirely sure. Something like this should work:
public MoveToRotation ()
{
Quaternion newDir = Quaternion.identity;
newDir.eulerAngles = new Vector3(0,angle,0);
transform.rotation = Quaternion.Slerp (transform.rotation, newDir, Time.deltaTime * torque);
rb.AddForce (transform.forward * acceleration);
}
This would mean you accel and slow down to get to a new rotation, but it’d probably feel awkward as players are often used to snapping controls, and the delay is a bit awkward. Basically you rotate faster for farther positions, so to get to point B fastest would mean to aim for C and stop early… Not the best, but its smooth for sure.
If all you want is a constant speed rotation, go with Lerp, it’s basically the same implementation I think.