From 8722a9920c1f6119bf6e769cba270e63097f8e25 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Thu, 23 May 2024 10:08:29 +0800 Subject: + astar project --- .../ExampleScripts/SmoothCameraFollow.cs | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/SmoothCameraFollow.cs (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/SmoothCameraFollow.cs') diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/SmoothCameraFollow.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/SmoothCameraFollow.cs new file mode 100644 index 0000000..80efdfb --- /dev/null +++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/ExampleScenes/ExampleScripts/SmoothCameraFollow.cs @@ -0,0 +1,37 @@ +using UnityEngine; + +namespace Pathfinding.Examples { + /// + /// Smooth Camera Following. + /// \author http://wiki.unity3d.com/index.php/SmoothFollow2 + /// + [HelpURL("https://arongranberg.com/astar/documentation/stable/smoothcamerafollow.html")] + public class SmoothCameraFollow : VersionedMonoBehaviour { + public Transform target; + public float distance = 3.0f; + public float height = 3.0f; + public float damping = 5.0f; + public bool enableRotation = true; + public bool smoothRotation = true; + public float rotationDamping = 10.0f; + public bool staticOffset = false; + + void LateUpdate () { + Vector3 wantedPosition; + + if (staticOffset) { + wantedPosition = target.position + new Vector3(0, height, distance); + } else { + wantedPosition = target.TransformPoint(0, height, -distance); + } + transform.position = Vector3.Lerp(transform.position, wantedPosition, Time.deltaTime * damping); + + if (enableRotation) { + if (smoothRotation) { + Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up); + transform.rotation = Quaternion.Slerp(transform.rotation, wantedRotation, Time.deltaTime * rotationDamping); + } else transform.LookAt(target, target.up); + } + } + } +} -- cgit v1.1-26-g67d0