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

deceleration

deceleration 函数是 Yuka.js 库中 ArriveBehavior(一个行为组件)的一部分。它用于计算减速到达目标点的速度。该函数将根据当前速度和距离目标点的距离计算所需的减速度。

语法

deceleration(currentVelocity, distance)

参数

  • currentVelocity: 当前速度,单位为米每秒(m/s)。
  • distance: 到达目标点的距离,单位为米(m)。

返回值

  • 返回一个表示减速度的数字,单位为米每二次方秒(m/s²)。

示例

const distance = 10; // 距离目标点10米
const currentVelocity = 5; // 当前速度为5 m/s
const deceleration = ArriveBehavior.deceleration(currentVelocity, distance);

console.log(deceleration); // 输出2.5

注意事项

  • 参数 currentVelocity 必须为正数。
  • 函数的返回值将被用于计算带有减速行为的运动的加速度。