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 库中的行为类之一,在游戏开发领域中常用于追逐目标对象。当目标对象在追逐者的视野内时,active 行为会使追逐者朝向目标对象并加速移动,直到追上目标对象。

使用方法

使用 active 行为需要将其添加到具有运动能力的实体身上,并将目标对象设置为 target 属性。目标对象可以是另一个实体、一个坐标点或一个函数,返回一个坐标点。此外,还需要设置 pursueDistance 属性,该属性表示追逐者将停止追击并返回其初始状态的距离。

import { PursuitBehavior } from 'yuka';

class Agent {
  constructor() {
    this.steering = new PursuitBehavior();
    this.steering.target = someEntity; // 或者 someVector2
    this.steering.pursueDistance = 10;
  }

  update( delta ) {
    this.steering.active = true;
    this.steering.calculate( this );
    this.velocity.add( this.steering.steeringForce );
    // 其它运动相关逻辑...
  }
}

属性

active:Boolean

标识当前行为是否处于激活状态。

target:Entity、Vector2或Function

指定目标对象,可以是另一个实体、一个坐标点或一个返回坐标点的函数。

pursueDistance:Number

指定追逐距离,如果追逐者与目标的距离小于该值,追逐者将停止追击并返回其初始状态。

方法

calculate( agent: Agent )

计算操纵向量,并将其作为 steeringForce 属性返回。

示例

您可以使用以下链接中的在线示例来进一步理解 active 行为的使用。

https://yangsihan.github.io/yuka-chasing-example/

参考

更多关于 active 行为的详细信息可以在以下链接中找到:

https://github.com/Mugen87/yuka/blob/master/docs/behavior/PursuitBehavior.md#active