Hi,
I am making a top down 2D game and i want my sprite to rotate on the Z-Axis depending on what direction it is moving. This is my code so far. I am still a beginner any help is appreciated.
public class PlayerController : MonoBehaviour {
public float speed;
private Rigidbody2D rigBod;
private Vector2 moveVelocity;
void Start ()
{
rigBod = GetComponent<Rigidbody2D>();
}
void Update()
{
if (GameObject.Find("GameManager").GetComponent<GameManager>().gameState == true)
{
PlayerControls();
}
}
void FixedUpdate()
{
if (GameObject.Find("GameManager").GetComponent<GameManager>().gameState == true)
{
PlayerMovement();
}
}
void PlayerControls()
{
Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
moveVelocity = moveInput.normalized * speed;
}
void PlayerMovement()
{
rigBod.MovePosition(rigBod.position + moveVelocity * Time.fixedDeltaTime);
}
}