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

active

active(感知障碍物并躲避) 是Yuka js库中的一种行为(Behavior), 用于使实体(Entity)在运动时感知并避开障碍物。这种行为可以应用于实体的移动或路径规划,从而使其在动态环境中更加智能和自适应。

使用方法

要使用 active 行为,需要将其添加到目标实体中。此外,还需要确保实体具有感知和移动能力(例如,有感知范围、有移动速度等)。

import { Entity, ObstacleAvoidanceBehavior } from 'yuka';

const entity = new Entity();
entity.velocity.set(1, 1, 0); // 设置实体的移动速度

const obstacleAvoidance = new ObstacleAvoidanceBehavior();
entity.steering.add(obstacleAvoidance); // 将ObstacleAvoidanceBehavior添加至实体的行为列表中

在实体运动时,active 行为会感知可见范围内的障碍物,并尝试躲避它们。

参数说明

active 行为可以接受一些配置参数,以便影响实体的行为。

  • avoidMargin:用于调整实体与其他物体之间的避让距离。
  • collisionRadius:实体的半径,用于判断实体是否和障碍物发生碰撞。
  • maxAcceleration:实体在避开障碍物时最大的加速度。
  • maxSpeed:实体在避开障碍物时的最大速度。
const obstacleAvoidance = new ObstacleAvoidanceBehavior({
  avoidMargin: 5,
  collisionRadius: 10,
  maxAcceleration: 20,
  maxSpeed: 10,
});
entity.steering.add(obstacleAvoidance);

行为结果

active 行为会根据感知到的障碍物在实体的运动上产生影响,从而使实体避开障碍物,保持一定的安全距离。因此,实体的运动轨迹可能会发生变化,从而导致实体绕开了障碍物并到达目的地。

结论

通过 active 行为,Yuka js库提供了一种智能感知和躲避障碍物的行为。使用者可以灵活调整参数以控制实体的行为,从而适应不同场景和需求。