A* Find and move towards nearest node

nathanj

Active member
Here's a little script to find the nearest A* Path node and store it as a local value. It borrows from the Get and Set Vector3 tasks so Justin, if you want to remove this feel free.

Hopefully it helps someone.

Edit. This should probably go in the Integrations area.

Code:
namespace BehaviorDesigner.Runtime.Tasks.Movement.AstarPathfindingProject
{
   
[TaskDescription("Search for the nearest AStart Path Node")]
    [TaskCategory("Movement/A* Pathfinding Project")]
    class AStarFindNearestNode : Action
    {
        
        [Tooltip("The Vector3 to get the values of")]
        public SharedVector3 getVector3Variable;
        [Tooltip("The Vector3 to set the values of")]
        public SharedVector3 setVector3Variable;

        public override TaskStatus OnUpdate()
        {
            GraphNode node = AstarPath.active.GetNearest(transform.position).node;
            getVector3Variable = (Vector3)node.position;
            setVector3Variable.Value = getVector3Variable.Value;
            return base.OnUpdate();
        }
    }
}
 
Last edited:
Top