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是Yuka js库的一个行为(Behavior),它用于在每次更新实体时计算实体的当前状态。

使用

要使用calculate行为,需要将其添加到实体的行为列表中。当实体更新时,行为系统将自动调用该行为。

import { Entity, calculate } from 'yuka';

const entity = new Entity();
entity.setBehavior( calculate );

参数

calculate行为没有任何参数。

工作原理

calculate行为具有override(重写)方法calculate(),该方法将由行为系统在每次更新实体时调用。此方法的任务是计算实体的当前状态。

在开发中,您需要创建自定义实例和方法,以适应您的特定用例。以下是一个示例实现:

const myCalculateBehavior = {
    calculate: function ( entity, deltaTime ) {
        const data = entity.data;
        data.position.x += data.velocity.x * deltaTime;
        data.position.y += data.velocity.y * deltaTime;
        data.position.z += data.velocity.z * deltaTime;
    }
};

entity.setBehavior( myCalculateBehavior );

在上面的示例中,calculate()方法推进实体沿着其速度向量移动,从而更新位置;每次更新都是通过将时间步长(deltaTime)与速度相乘来完成的。

参考资料