diff options
author | chai <215380520@qq.com> | 2024-05-23 10:08:29 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-05-23 10:08:29 +0800 |
commit | 8722a9920c1f6119bf6e769cba270e63097f8e25 (patch) | |
tree | 2eaf9865de7fb1404546de4a4296553d8f68cc3b /Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Behaviors/MoveInCircle.cs | |
parent | 3ba4020b69e5971bb0df7ee08b31d10ea4d01937 (diff) |
+ astar project
Diffstat (limited to 'Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Behaviors/MoveInCircle.cs')
-rw-r--r-- | Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Behaviors/MoveInCircle.cs | 51 |
1 files changed, 51 insertions, 0 deletions
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 { + /// <summary> + /// 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 cref="AIDestinationSetter"/> + /// See: <see cref="FollowerEntity"/> + /// See: <see cref="AIPath"/> + /// See: <see cref="RichAI"/> + /// See: <see cref="AILerp"/> + /// </summary> + [UniqueComponent(tag = "ai.destination")] + [AddComponentMenu("Pathfinding/AI/Behaviors/MoveInCircle")] + /// <summary>[MoveInCircle]</summary> + [HelpURL("https://arongranberg.com/astar/documentation/stable/moveincircle.html")] + public class MoveInCircle : VersionedMonoBehaviour { + /// <summary>Target point to rotate around</summary> + public Transform target; + /// <summary>Radius of the circle</summary> + public float radius = 5; + /// <summary>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.</summary> + public float offset = 2; + + IAstarAI ai; + + void OnEnable () { + ai = GetComponent<IAstarAI>(); + } + + 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); + } + } + /// <summary>[MoveInCircle]</summary> +} |