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

该方法为SteeringBehavior的一个参数,用于调整某个特定行为(如抵达目的地、避免障碍物等)的权重。

语法

behavior.weight = value;
  • behavior: 指定的行为对象。
  • value: 该行为的权重值。

参数

  • value: 一个数字类型,目标行为在算法中所占的比重。根据需要进行调整,通常缺省值为1。

示例

var arriveBehavior = new YUKA.ArriveBehavior( target, 1 );
var avoidObstacleBehavior = new YUKA.AvoidObstacleBehavior( obstacle, 0.5 );

arriveBehavior.weight = 5;
avoidObstacleBehavior.weight = 2;

上面代码演示了如何在两个行为arriveBehavioravoidObstacleBehavior中设置权重值。

通过将arriveBehavior的权重值调整为5,其在算法中所占的比例就会增加,机器实体就会更加接近目标位置;同时将避免障碍行为的权重值调整为2,则在算法中所占比例降低,机器实体就会更加容易避障。

注意事项

  • 权重值范围建议控制在0至1之间,尽管该参数不会直接限制其取值。超过该范围的值可能会导致不符合预期的行为或算法崩溃。
  • 权重值的设定应该依据具体的场景进行灵活调整,达到期望的行为效果。