using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMovement : MonoBehaviour { public float moveSpeed = 5f; private Rigidbody2D rb; private Animator animator; private Vector2 movement; void Start() { rb = GetComponent(); animator = GetComponent(); } void Update() { movement.x = Input.GetAxisRaw("Horizontal"); movement.y = Input.GetAxisRaw("Vertical"); animator.SetFloat("Horizontal", movement.x); animator.SetFloat("Vertical", movement.y); animator.SetFloat("Speed", movement.sqrMagnitude); } void FixedUpdate() { movement.Normalize(); rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime); } }