From 8162e2fe30f20158fde8f4e3698e2561b947de39 Mon Sep 17 00:00:00 2001 From: Eicy Date: Wed, 11 Sep 2024 14:06:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=A9=E5=AE=B6=E7=A7=BB=E5=8A=A8=E9=80=9F?= =?UTF-8?q?=E5=BA=A6=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Player/PlayerMotion.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Player/PlayerMotion.cs b/Assets/Scripts/Player/PlayerMotion.cs index 1d579fe..e059e7c 100644 --- a/Assets/Scripts/Player/PlayerMotion.cs +++ b/Assets/Scripts/Player/PlayerMotion.cs @@ -1,5 +1,4 @@ -using System; -using Keyboard; +using Keyboard; using UnityEngine; namespace Player @@ -8,6 +7,7 @@ namespace Player { [SerializeField] private Rigidbody rb; [SerializeField] private Animator animator; + [SerializeField] private float maxVelocity; private Vector3 _velocity; private void Update() @@ -18,7 +18,15 @@ namespace Player private void Run() { _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); } } } \ No newline at end of file