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 --- .../Behaviors/MoveInCircle.cs | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Behaviors/MoveInCircle.cs (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Behaviors/MoveInCircle.cs') diff --git a/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Behaviors/MoveInCircle.cs b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Behaviors/MoveInCircle.cs new file mode 100644 index 0000000..9d5c464 --- /dev/null +++ b/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Behaviors/MoveInCircle.cs @@ -0,0 +1,51 @@ +using UnityEngine; +using Pathfinding.Drawing; + +namespace Pathfinding { + /// + /// Moves an agent in a circle around a point. + /// + /// This script is intended as an example of how you can make an agent move in a circle. + /// In a real game, you may want to replace this script with your own custom script that is tailored to your game. + /// The code in this script is simple enough to copy and paste wherever you need it. + /// + /// [Open online documentation to see videos] + /// + /// See: move_in_circle (view in online documentation for working links) + /// See: + /// See: + /// See: + /// See: + /// See: + /// + [UniqueComponent(tag = "ai.destination")] + [AddComponentMenu("Pathfinding/AI/Behaviors/MoveInCircle")] + /// [MoveInCircle] + [HelpURL("https://arongranberg.com/astar/documentation/stable/moveincircle.html")] + public class MoveInCircle : VersionedMonoBehaviour { + /// Target point to rotate around + public Transform target; + /// Radius of the circle + public float radius = 5; + /// Distance between the agent's current position, and the destination it will get. Use a negative value to make the agent move in the opposite direction around the circle. + public float offset = 2; + + IAstarAI ai; + + void OnEnable () { + ai = GetComponent(); + } + + void Update () { + var normal = (ai.position - target.position).normalized; + var tangent = Vector3.Cross(normal, target.up); + + ai.destination = target.position + normal * radius + tangent * offset; + } + + public override void DrawGizmos () { + if (target) Draw.Circle(target.position, target.up, radius, Color.white); + } + } + /// [MoveInCircle] +} -- cgit v1.1-26-g67d0