AABB
AlignmentBehavior
ArriveBehavior
AStar
BFS
BoundingSphere
BVH
BVHNode
Cell
CellSpacePartitioning
CohesionBehavior
CompositeGoal
ConvexHull
Corridor
CostTable
DFS
Dijkstra
Edge
EntityManager
EvadeBehavior
EventDispatcher
Behavior
FollowPathBehavior
FuzzyAND
FuzzyCompositeTerm
FuzzyFAIRLY
FuzzyModule
FuzzyOR
FuzzyRule
FuzzySet
FuzzyTerm
FuzzyVariable
FuzzyVERY
GameEntity
Goal
GoalEvaluator
Graph
GraphUtils
HalfEdge
HeuristicPolicyDijkstra
HeuristicPolicyEuclid
HeuristicPolicyEuclidSquared
HeuristicPolicyManhattan
InterposeBehavior
LeftSCurveFuzzySet
LeftShoulderFuzzySet
LineSegment
Logger
MathUtils
Matrix3
Matrix4
MemoryRecord
MemorySystem
MeshGeometry
MessageDispatcher
MovingEntity
NavEdge
NavMesh
NavMeshLoader
NavNode
Node
NormalDistFuzzySet
OBB
ObstacleAvoidanceBehavior
OffsetPursuitBehavior
OnPathBehavior
Path
Plane
Polygon
Polyhedron
PriorityQueue
PursuitBehavior
Quaternion
Ray
RectangleTriggerRegion
Regular
RightSCurveFuzzySet
RightShoulderFuzzySet
SAT
SeekBehavior
SeparationBehavior
SingletonFuzzySet
Smoother
SphericalTriggerRegion
State
StateMachine
SteeringBehavior
SteeringManager
Task
TaskQueue
Telegram
Think
Time
TriangularFuzzySet
Trigger
TriggerRegion
Vector3
Vehicle
Version
WanderBehavior

getPath

描述

AStar类的getPath方法被用于获取从起点到终点的最短路径。

语法

AStar.getPath(startNode, endNode, diagonalsAllowed)

参数

  • startNode:必需,起点节点对象。
  • endNode:必需,终点节点对象。
  • diagonalsAllowed:可选,布尔值,表示是否允许斜向移动。默认为false,即不允许。

返回值

  • 如果找到最短路径,返回一个由节点组成的数组,包括起点和终点。
  • 如果没有找到路径,则返回null。

示例

var startNode = new Node(0, 0);
var endNode = new Node(5, 5);
var astar = new AStar(map);
var path = astar.getPath(startNode, endNode);
if (path === null) {
    console.log("No path found!");
} else {
    console.log(path);
}

注意事项

  • 引用AStar类之前,请确保已经引用了Node和Map类。
  • 起点和终点节点对象都必须在地图范围内。
  • 如果允许斜向移动,则路径可能不是唯一的最短路径。