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

calculate

函数描述:

HeuristicPolicyManhattan的calculate方法是用来计算两点之间的曼哈顿距离的函数。

函数参数:

  • startX: number类型,起点的x坐标。
  • startY: number类型,起点的y坐标。
  • endX: number类型,终点的x坐标。
  • endY: number类型,终点的y坐标。

返回值:

  • 返回两点之间的曼哈顿距离,number类型。

函数示例:

var startX = 0;
var startY = 0;
var endX = 3;
var endY = 4;
var heuristic = new Yuka.HeuristicPolicyManhattan();
var distance = heuristic.calculate(startX, startY, endX, endY);
console.log(distance); // 7

示例说明:

本示例演示了如何使用HeuristicPolicyManhattan的calculate方法计算起点和终点之间的曼哈顿距离。startXstartY分别代表起点的x和y坐标,endXendY分别代表终点的x和y坐标。heuristic是一个新建的HeuristicPolicyManhattan实例,调用其calculate方法,传入起点和终点的坐标,计算出曼哈顿距离并将结果存入distance中,最后在控制台输出结果。本示例中,起点和终点之间的曼哈顿距离为7。