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

nextWaypointDistance

功能

该函数用于判断当前移动对象到达下一个路径点的距离是否小于设定的距离阈值。

语法

nextWaypointDistance (entity, threshold)

参数

  • entity:必选参数,移动对象实体。
  • threshold:必选参数,判断距离的阈值,单位为像素。

返回值

  • 如果当前移动对象距离下一个路径点的距离小于等于设定的距离阈值,则返回 true
  • 如果当前移动对象距离下一个路径点的距离大于设定的距离阈值,则返回 false

示例

const entity = new Yuka.Entity();
const path = new Yuka.Path();
// add waypoints to the path

const threshold = 10;
const followPathBehavior = new Yuka.FollowPathBehavior( entity, path );
// other configuration for the behavior

if ( followPathBehavior.nextWaypointDistance( entity, threshold ) ) {
  console.log( 'Next waypoint reached.' );
}

注意事项

  • 如果阈值设置得太小,则可能无法到达下一个路径点。
  • 如果阈值设置得太大,则可能会导致移动对象超越下一个路径点而无法停下来。