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

offset

简介

OffsetPursuitBehavior是Yuka js库中的一种行为。它可以将实体引导到目标点,同时可以为实体提供偏移量。

用法

OffsetPursuitBehavior会尝试引导实体靠近目标点,但同时会为实体添加一个偏移量。这个偏移量可以调整实体行动的方向和速度。

偏移量的计算方式为:

offset = target.position.clone().sub(leader.position);

这里的leader是实体(Entity),target是目标点(Vector3)。

示例代码

import { OffsetPursuitBehavior, Entity } from 'yuka';

const leader = new Entity();
const target = new THREE.Vector3( 10, 0, 20 );

const behavior = new OffsetPursuitBehavior( target, 5 );
leader.steering.add( behavior );

// 在 update 函数中更新 leader 的位置和朝向
function update() {
    leader.update( delta );
}

在这个示例中,我们创建了一个Entity,并给它添加了一个OffsetPursuitBehavior。这个行为会将leader引导向目标点target,并为实体添加了偏移量5。我们在update函数中,每帧都给leader更新位置和朝向。

参数

  • target: 目标点(Vector3)
  • offset: 偏移量

返回值

OffsetPursuitBehavior没有返回值。

注意事项

  • OffsetPursuitBehavior是一种基础行为,它可以与其他行为组合使用,以实现更多复杂的行为。
  • 调整偏移量的值可以影响实体的行动方向和速度,可以根据需要来调整。
  • OffsetPursuitBehavior会尝试引导实体靠近目标点,但可能会导致实体脱离其它行为的引导,从而出现不理想的行为。因此,需要根据实际需求来决定是否使用OffsetPursuitBehavior。