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

calculate函数是SteeringManager类的一个方法,用于计算一个物体进行移动时,在给定速度和方向的情况下,需要施加哪些力来完成移动。

语法

calculate(currentVelocity, maxVelocity, steeringDirection, deceleration, deltaTime);

参数

currentVelocity: Vector2类型,表示当前物体的速度向量。

maxVelocity: Number类型,表示物体允许的最大速度。

steeringDirection: Vector2类型,表示目标方向.

deceleration: Number类型,表示物体减速的速率。

deltaTime: Number类型,表示计算距离上一次计算所经过的时间。

返回值

函数返回一个Vector2类型的向量,表示需要施加的力。

示例

const steeringManager = new SteeringManager();
const currentVelocity = new Vector2(10, 5);
const maxVelocity = 20;
const steeringDirection = new Vector2(1, 0);
const deceleration = 1.5;
const deltaTime = 0.0167; // 60 FPS的情况下,一帧的时间

const steeringForce = steeringManager.calculate(currentVelocity, maxVelocity, steeringDirection, deceleration, deltaTime);

在上面的示例中,currentVelocity表示当前物体的速度向量,maxVelocity表示物体允许的最大速度,steeringDirection表示物体目标方向,deceleration表示物体减速的速率,deltaTime表示计算距离上一次计算所经过的时间。calculate函数将返回一个steeringForce变量,表示需要施加的力。