32 lines
973 B
C#
32 lines
973 B
C#
using Keyboard;
|
|
using UnityEngine;
|
|
|
|
namespace Player
|
|
{
|
|
public class PlayerMotion : MonoBehaviour
|
|
{
|
|
[SerializeField] private Rigidbody rb;
|
|
[SerializeField] private Animator animator;
|
|
[SerializeField] private float maxVelocity;
|
|
private Vector3 _velocity;
|
|
|
|
private void Update()
|
|
{
|
|
Run();
|
|
}
|
|
|
|
private void Run()
|
|
{
|
|
_velocity = KeySettingManager.Instance.Direction.x * transform.right + KeySettingManager.Instance.Direction.y * transform.forward;
|
|
rb.AddForce(_velocity.normalized * (Time.deltaTime * 50), ForceMode.Impulse);
|
|
if (_velocity == Vector3.zero)
|
|
{
|
|
var temp = rb.velocity;
|
|
temp = Vector3.ClampMagnitude(temp, 2);
|
|
temp.y = rb.velocity.y;
|
|
rb.velocity = temp;
|
|
}
|
|
rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxVelocity);
|
|
}
|
|
}
|
|
} |