From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/TracerTarget.cs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 GameCode/TracerTarget.cs (limited to 'GameCode/TracerTarget.cs') diff --git a/GameCode/TracerTarget.cs b/GameCode/TracerTarget.cs new file mode 100644 index 0000000..19b6b67 --- /dev/null +++ b/GameCode/TracerTarget.cs @@ -0,0 +1,65 @@ +using UnityEngine; + +public class TracerTarget : MonoBehaviour +{ + private MoveTransform move; + + public bool hasPos; + + public float drag; + + public float spring; + + public AnimationCurve curve; + + public float cosScale = 1f; + + public float cosAmount; + + private float random; + + private float c; + + private bool done; + + private Vector3 tPos; + + private Vector3 upDir; + + private MoveTransform mTrans; + + private void Start() + { + move = GetComponent(); + random = Random.Range(0f, 1000f); + SetPos(base.transform.forward * 100f, base.transform.up, null); + } + + private void Update() + { + float num = 1f; + if ((bool)mTrans) + { + num += mTrans.velocity.magnitude * 0.1f; + } + if ((bool)mTrans && !done) + { + tPos += base.transform.forward + base.transform.forward * 10f; + } + c += TimeHandler.deltaTime; + if (hasPos) + { + move.velocity += cosAmount * Mathf.Cos((Time.time + random) * cosScale) * upDir * CappedDeltaTime.time / num; + move.velocity += (tPos - base.transform.position).normalized * spring * CappedDeltaTime.time * curve.Evaluate(c) * num; + move.velocity -= move.velocity * CappedDeltaTime.time * drag * curve.Evaluate(c); + } + } + + public void SetPos(Vector3 targetPos, Vector3 up, MoveTransform move) + { + mTrans = move; + hasPos = true; + tPos = targetPos; + upDir = up; + } +} -- cgit v1.1-26-g67d0