[Player] Add AI Pathfinding on a 2D grid to the player character

This commit is contained in:
Michal Pikulski
2025-09-02 11:42:25 +02:00
parent 3d3b72f04d
commit e53b5a0034
663 changed files with 148320 additions and 66 deletions

View File

@@ -0,0 +1,21 @@
using UnityEngine;
using System.Collections;
using Pathfinding;
/// <summary>
/// Helper editor script to snap an object to the closest node.
/// Used in the "Turn Based" example scene for snapping obstacles to the hexagon grid.
/// </summary>
[ExecuteInEditMode]
[HelpURL("http://arongranberg.com/astar/docs/class_snap_to_node.php")]
public class SnapToNode : MonoBehaviour {
void Update () {
if (transform.hasChanged && AstarPath.active != null) {
var node = AstarPath.active.GetNearest(transform.position, NNConstraint.None).node;
if (node != null) {
transform.position = (Vector3)node.position;
transform.hasChanged = false;
}
}
}
}