This is my code the character is normally facing right, but I want the character to turn when he walks left. How do I do this? I have tried to search and look at guides but they either make my character transform in weird angels or doesn’t work at all. Please help, thanks in advance!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
public Animator animator;
public Rigidbody2D rb;
private Vector2 moveDirection;
void Update()
{
float moveX = Input.GetAxisRaw("Horizontal");
float moveY = Input.GetAxisRaw("Vertical");
animator.SetFloat("Speed", Mathf.Abs(moveDirection.x + moveDirection.y));
moveDirection = new Vector2(moveX, moveY).normalized;
}
void FixedUpdate()
{
rb.velocity = new Vector2(moveDirection.x * moveSpeed, moveDirection.y * moveSpeed);
}
}