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

update

在Yuka js库的GameEntity类中,update()方法用于更新实体的状态。该方法每帧都会被调用一次。

语法

update( delta: number ): void;

参数:

  • delta: number: 时间步长,单位为毫秒。

返回值:

  • void

示例

import { GameEntity } from 'yuka';

class MyEntity extends GameEntity {
    update( delta ) {
        // 更新实体状态的代码
    }
}

描述

update()方法主要用于更新实体的状态,例如位置、速度等。

在update()方法中可以访问实体的属性和方法,例如position、velocity、setHeading()等。

update()方法中的delta参数表示时间步长,即上一帧和这一帧之间的时间间隔。通过delta参数可以保证实体状态的更新不会受到帧率变化的影响,使得实体的运动效果更加平滑自然。

注意事项

  • update()方法每帧都会被调用一次,因此要避免在该方法中执行过于复杂或耗时的操作,以免对性能造成影响。

  • update()方法中的delta参数应该与时间有关,而不是帧数。因此应该使用performance.now()等方法来获取时间信息,而不是使用帧率。

  • 如果实体的运动是基于物理引擎的,那么update()方法一般应该调用物理引擎的update()方法来更新实体状态。