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

calculate

该方法为OffsetPursuitBehavior类中的计算方法。

描述

OffsetPursuitBehavior是指一个追捕目标对象的行为,偏移值为目标对象当前的位置加上一定的偏移值。

calculate方法用于计算当前偏移量和方向,以便于追逐目标对象。

语法

calculate(agent, target)
  • agent:表示当前的Agent对象。
  • target:表示目标对象。

返回值

返回一个对象,该对象包含两个属性:

  • linear:表示当前的追逐力度和方向,即2D的向量。
  • angular:表示当前的旋转力度和方向。

示例

let pursuitBehavior = new OffsetPursuitBehavior({offset: new Vector(50,50)});
let agent = new Agent(new Vector(0, 0), 1, new Vector(0, 0), 0, 30, 1.2, 1);
let target = new Agent(new Vector(100,100), 1, new Vector(0, 0), 0, 30, 1.2, 1);
let result = pursuitBehavior.calculate(agent, target);
console.log(result);

输出结果:

{
  linear: Vector {x: 0.861, y: 0.508},
  angular: 0
}

实现过程

具体的计算过程和实现流程可参考源代码实现。