using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

    public float MoveSpeed = 5f;

    public Rigidbody2D rb;

    Vector2 movement;

    public float RotationSpeed = 5f;

    // Update is called once per frame
    void Update()
    {
        PlayerInput();
    }

    private void FixedUpdate()
    {
        PlayerMove();
        RotatePlayer();
    }

    private void PlayerInput()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
    }

    private void PlayerMove()
    {
        rb.velocity = transform.right * Mathf.Clamp01(movement.y) * MoveSpeed;
    }

    private void RotatePlayer()
    {
        float rotation = -movement.x * RotationSpeed;
        transform.Rotate(Vector3.forward * rotation);
    }
     
}