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

weight

本文档描述了FollowPathBehavior的权重(weight)属性。该属性用于控制行为在复合行为中的优先级。

语法

behavior.weight = <number>;
  • behavior:FollowPathBehavior对象
  • weight:权重值,必须为一个数值类型

默认值

默认值为0。

描述

在一个复合行为内,可能存在多个行为,这些行为的执行顺序将由它们的权重值决定。weight的值越大,则该行为的执行优先级越高。当多个行为的weight值相同时,则它们的执行顺序是无法保证的。

示例

const behavior1 = new FollowPathBehavior();
behavior1.weight = 0;

const behavior2 = new FollowPathBehavior();
behavior2.weight = 1;

const compositeBehavior = new CompositeBehavior();
compositeBehavior.addChild(behavior1);
compositeBehavior.addChild(behavior2);

//优先执行behavior2

在这个示例中,compositeBehavior中包含两个行为behavior1和behavior2,它们分别对应FollowPathBehavior对象。由于behavior2的权重值大于behavior1,所以在复合行为compositeBehavior中,behavior2的优先级高于behavior1。

注意事项

  • 权重值为负数时,视为0处理。

  • 如果多个行为的weight都为0,则它们的执行顺序是无法保证的。