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

obstacles

介绍

obstacles是Yuka js库中ObstacleAvoidanceBehavior类的一个属性,用于设置避障行为中的障碍物集合。

语法

behavior.obstacles = [obstacle1, obstacle2, ...];

其中,behaviorObstacleAvoidanceBehavior类的实例化对象,obstacle1, obstacle2, ...为障碍物对象集合。

类型

obstacles为一个数组类型,其中的每个元素为障碍物对象。

参数

障碍物对象的参数如下:

参数名 类型 描述 必填
radius Number 障碍物的半径
position Vector3 障碍物的位置
direction Vector3 障碍物的运动方向
speed Number 障碍物的运动速度

示例

// 实例化一个ObstacleAvoidanceBehavior对象
const behavior = new ObstacleAvoidanceBehavior();

// 定义障碍物对象
const obstacle1 = {
  radius: 10,
  position: new Vector3(50, 0, -100),
  direction: new Vector3(1, 0, 0),
  speed: 50
};
const obstacle2 = {
  radius: 15,
  position: new Vector3(-30, 0, -50),
  direction: new Vector3(0.5, 0, 1),
  speed: 30
};

// 设置障碍物集合
behavior.obstacles = [obstacle1, obstacle2];

以上示例中,定义了两个障碍物对象,并通过behavior.obstacles属性设置了障碍物集合。