Player should turn in the direction the player is running. (2D Game)
Hey, Does anyone know what I did wrong with this script? Can anyone help me?
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private float speed;
private Rigidbody2D body;
private void Awake()
{
body = GetComponent<Rigidbody2D>();
}
private void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
//Dreht den Spieler
if (horizontalInput > 0,01f)
{
transform.localScale = Vector3.one;
}
else if (horizontalInput < 0,01f)
{
transform.localScale = new Vector3(-1, 1, 1);
}
if (Input.GetKey(KeyCode.Space))
{
body.velocity = new Vector2(body.velocity.x, speed);
}
}
Comment