diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/PlayerWobblePosition.cs |
+ init
Diffstat (limited to 'GameCode/PlayerWobblePosition.cs')
-rw-r--r-- | GameCode/PlayerWobblePosition.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/GameCode/PlayerWobblePosition.cs b/GameCode/PlayerWobblePosition.cs new file mode 100644 index 0000000..6d05434 --- /dev/null +++ b/GameCode/PlayerWobblePosition.cs @@ -0,0 +1,38 @@ +using UnityEngine; + +public class PlayerWobblePosition : MonoBehaviour +{ + private Vector3 physicsPos; + + public float drag = 15f; + + public float spring = 1000f; + + public float multiplier = 1f; + + public float prediction; + + private Vector3 velocity; + + private Player player; + + private void Start() + { + physicsPos = base.transform.position; + player = GetComponentInParent<Player>(); + } + + private void Update() + { + float num = Mathf.Clamp(TimeHandler.deltaTime, 0f, 0.03f); + Vector3 position = player.transform.position; + if (prediction > 0f) + { + position += (Vector3)player.data.playerVel.velocity * prediction; + } + velocity += (position - physicsPos) * num * spring; + velocity -= velocity * drag * num; + physicsPos += num * multiplier * velocity; + base.transform.position = physicsPos; + } +} |