I've made a very simple 2D top down prototype with Unity. This is the code I use for the player:
public class PlayerTurnsController : MonoBehaviour
{
private Rigidbody2D m_rb;
public float Speed;
Vector2 m_movement;
void Start()
{
m_rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
var moveHorizontal = Input.GetAxis("Horizontal");
var moveVertical = Input.GetAxis("Vertical");
m_movement = new Vector2(moveHorizontal, moveVertical);
}
void FixedUpdate()
{
m_rb.MovePosition(m_rb.position + m_movement * Speed * Time.fixedDeltaTime);
}
}
At the start and while moving everything seems OK. But when I bump into some Colliders, the player sprite starts spinning when it should just stop (not pressing any button anymore)
I already tried:
- To set the rotation only when the m_Movement-Vector is > 0.1f. But this didn't change anything.
freezeRotation
andAddTorque
a little lower down). I'd recommend doing a bit more searching and experimentation in future. Trust in your own ability to solve problems. You got this! :) \$\endgroup\$ – DMGregory♦ Jul 5 '20 at 17:58