SpringSpeedFollow.cs 756 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using UnityEngine;
  3. namespace BasicTools
  4. {
  5. public class SpringSpeedFollow : MonoBehaviour
  6. {
  7. private void Start()
  8. {
  9. if (this.followed == null)
  10. {
  11. this.followed = base.transform;
  12. }
  13. }
  14. private void Update()
  15. {
  16. Vector3 vector = this.followed.transform.position - base.transform.position;
  17. vector.Scale(this.speedScale);
  18. base.transform.position += vector;
  19. Vector3 b = vector - this.maxDeltaDistance;
  20. b.x = Mathf.Clamp(b.x, 0f, float.MaxValue);
  21. b.y = Mathf.Clamp(b.y, 0f, float.MaxValue);
  22. b.z = Mathf.Clamp(b.z, 0f, float.MaxValue);
  23. base.transform.position += b;
  24. }
  25. public Transform followed;
  26. public Vector3 speedScale;
  27. public Vector3 maxDeltaDistance;
  28. }
  29. }