diff options
| author | SmallFox <2806143047@qq.com> | 2026-01-30 23:10:03 +0800 |
|---|---|---|
| committer | SmallFox <2806143047@qq.com> | 2026-01-30 23:10:03 +0800 |
| commit | 28fbde36e76429bfb2bf577d9e3da77db745ef3d (patch) | |
| tree | 03392014566a11be31f8bfe59b3a5416e7ce33a2 /Assets/Scripts/PlayerMovement.cs | |
| parent | 87aacebb8431b402d6a18054a81c4542632008d7 (diff) | |
| parent | bdd0c3eee905c5dc6fcf22344f7fdbd4cc3e3a02 (diff) | |
Merge branch 'main' of catilgrass.cn:GameJamTemplate into dev_lys
Diffstat (limited to 'Assets/Scripts/PlayerMovement.cs')
| -rw-r--r-- | Assets/Scripts/PlayerMovement.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Assets/Scripts/PlayerMovement.cs b/Assets/Scripts/PlayerMovement.cs new file mode 100644 index 0000000..90252b3 --- /dev/null +++ b/Assets/Scripts/PlayerMovement.cs @@ -0,0 +1,37 @@ +using System; +using UnityEngine; + +[RequireComponent(typeof(PlayerControl))] +[RequireComponent(typeof(Rigidbody))] +public class PlayerMovement : MonoBehaviour +{ + public float movementSpeed; + public float movementSpeedOnGrabbing; + + private PlayerControl _playerControl; + private Rigidbody _rigidbody; + + private void Awake() + { + _playerControl = GetComponent<PlayerControl>(); + _rigidbody = GetComponent<Rigidbody>(); + } + + private void FixedUpdate() + { + FixedUpdateMovement(); + } + + private void FixedUpdateMovement() + { + var velocity = _rigidbody.linearVelocity; + var speed = _playerControl.grabbing ? movementSpeedOnGrabbing : movementSpeed; + var direction = new Vector3( + _playerControl.movementHorizontal, + 0, + _playerControl.movementVertical) + .normalized; + var playerVelocity = speed * direction + velocity.y * Vector3.up; + _rigidbody.linearVelocity = playerVelocity; + } +} |
