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

rotation

描述

rotation是Yuka.js库中的一个触发器类,用于检测对象的旋转变化。

构造函数

constructor()

创建一个rotation对象实例。

const rotationTrigger = new YUKA.rotation();

属性

threshold

指定旋转变化的最小阈值。默认值为0.。

rotationTrigger.threshold = 0.1;

axis

指定旋转变化所围绕的轴。默认为Y轴。

// 围绕Z轴旋转
rotationTrigger.axis.set(0, 0, 1);

方法

update(entity)

检查给定对象的旋转变化是否超过了指定的阈值。如果是,则返回true并触发事件。否则,返回false

const entity = new YUKA.Entity();
entity.rotation.set(Math.PI / 4, 0, 0);

if (rotationTrigger.update(entity)) {
  // 触发事件
}

reset()

重置所有内部状态。

rotationTrigger.reset();

事件

change

旋转变化事件,当检测到对象的旋转变化超过了指定的阈值时,将触发此事件。

rotationTrigger.addEventListener('change', (entity) => {
  console.log('触发了旋转变化事件!');
});

示例

const rotationTrigger = new YUKA.rotation();
const entity = new YUKA.Entity();
entity.rotation.set(Math.PI / 4, 0, 0);
rotationTrigger.threshold = 0.1;

if (rotationTrigger.update(entity)) {
  console.log('检测到对象的旋转变化!');
}

rotationTrigger.addEventListener('change', (entity) => {
  console.log('触发了旋转变化事件!');
});

entity.rotation.set(Math.PI / 2, 0, 0);

if (rotationTrigger.update(entity)) {
  console.log('检测到对象的旋转变化!');
}

参考链接