From 343a1aa731a85a8a866d0466d29931e5a9c8dfb0 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 31 Jan 2026 11:10:04 +0800 Subject: 完成了罗师傅的移动系统 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/PlayerRotationController.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'Assets/Scripts/PlayerRotationController.cs') diff --git a/Assets/Scripts/PlayerRotationController.cs b/Assets/Scripts/PlayerRotationController.cs index d43ef36..e339116 100644 --- a/Assets/Scripts/PlayerRotationController.cs +++ b/Assets/Scripts/PlayerRotationController.cs @@ -3,5 +3,26 @@ using UnityEngine; public class PlayerRotationController : MonoBehaviour { - + [Range(0, 1)] public float lerpSpeed = 0.25f; + public Transform lookAt; + public PlayerControl control; + + private readonly float _len = 5f; + private Vector3 _target; + + private void Update() + { + var dir = new Vector3(control.movementHorizontal, 0, control.movementVertical).normalized; + if (dir != Vector3.zero) + { + _target = dir * _len; + // lookAt.localPosition = _target; + } + } + + private void FixedUpdate() + { + var pos = lookAt.localPosition; + lookAt.localPosition = Vector3.Lerp(pos, _target, lerpSpeed); + } } -- cgit