Vector3.RotateTowards doesn't work with angles of 180 degrees
I'm trying to use Vector3.RotateTowards to rotate a Vector2 towards another Vector2. Using the following code gives me a weird bug. I'm trying to use this for turning because I want to be able to control how fast the rotation speed is. Lerp doesn't work for me because I don't want the smooth fast to slow movement.
private void Update()
{
// Get movement vector from input
m_inputDirection = movementInput.ReadValue<Vector2>();
// Lerp the direction we want our player to head in from input direction
m_direction = Vector3.RotateTowards(m_direction, m_inputDirection, turnSpeed, 0.0f);
m_direction.Normalize();
Debug.DrawLine(transform.position, m_inputDirection, new Color(0, 0, 1));
Debug.DrawLine(transform.position, m_direction, new Color(1, 0, 0));
}
The code works perfectly until m_direction is in the opposite direction as m_inputDirection. (Whenever they are at exactly 180 degrees of each other) Otherwise, nothing happens and the vector does not rotate.
m_inputDirection is just a Vector2 created from inputs from the keyboard.
Your answer
Follow this Question
Related Questions
Unity 2D - Rotating the controls themselves 0 Answers
Smooth rotation problem 1 Answer
Unity 2D rotation not smooth? 0 Answers
Rotate camera on collision of character 1 Answer
Space/Aircraft rotation 0 Answers