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

介绍

weightWanderBehavior 类中用于指定行为权重的属性。

WanderBehavior 中,通过给不同行为设置不同的权重,控制该行为出现的散步概率,从而实现了更加智能的散步。

类型

weight 是一个数字类型的属性。

默认值

weight 的默认值是 1

取值范围

weight 的取值范围是从 0 到无穷大,其中值为 0 的权重代表该行为不会被执行。

使用方法

下面是一个使用 weight 属性的示例代码:

const wanderBehavior = new Yuka.WanderBehavior();
wanderBehavior.weight = 2;

在上述代码中,我们为 wanderBehavior 设置了 weight 属性的值为 2,这代表该行为出现的概率比默认的 1 更高。

场景案例

假如我们希望实现玩家在游戏中随意散步的效果,但又不希望每次散步的路径都相同,那么我们可以通过修改 WanderBehavior 中各个行为的 weight 属性来控制散步路径的多样性。

比如,我们可以让 WanderBehavior 中的 randomDirection 行为的权重为 1, randomSphereSurface 行为的权重为 2distanceThreshold 行为的权重为 3,这样就可以让玩家在散步时更加随意自由,不同的行为组合也会呈现出不同的散步路径。

结语

weight 属性是 WanderBehavior 类中极其重要的一个属性,通过设置不同的权重,我们可以实现更加智能的散步,让游戏玩家在游戏中体验到更加自由和随意的感觉。