玩家移动速度限制
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using Keyboard;
|
||||||
using Keyboard;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Player
|
namespace Player
|
||||||
@@ -8,6 +7,7 @@ namespace Player
|
|||||||
{
|
{
|
||||||
[SerializeField] private Rigidbody rb;
|
[SerializeField] private Rigidbody rb;
|
||||||
[SerializeField] private Animator animator;
|
[SerializeField] private Animator animator;
|
||||||
|
[SerializeField] private float maxVelocity;
|
||||||
private Vector3 _velocity;
|
private Vector3 _velocity;
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
@@ -18,7 +18,15 @@ namespace Player
|
|||||||
private void Run()
|
private void Run()
|
||||||
{
|
{
|
||||||
_velocity = KeySettingManager.Instance.Direction.x * transform.right + KeySettingManager.Instance.Direction.y * transform.forward;
|
_velocity = KeySettingManager.Instance.Direction.x * transform.right + KeySettingManager.Instance.Direction.y * transform.forward;
|
||||||
rb.AddForce(_velocity.normalized * (Time.deltaTime * 10), ForceMode.Impulse);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user