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

lookAt

lookAt() 方法用于计算四元数,将目标点定向至某一方向。

语法

Quaternion.lookAt(target, position, up);

参数

  • target:一个三维向量,表示目标点的位置。
  • position:一个三维向量,表示摄像机的位置。
  • up:一个三维向量,表示摄像机上方的向量。默认值为 Vector3(0, 1, 0)。

返回值

返回一个四元数(Quaternion)对象,表示摄像机从 position 方向朝向 target

示例

const target = new Yuka.Vector3(0, 0, 0);
const position = new Yuka.Vector3(0, 0, 10);
const up = new Yuka.Vector3(0, 1, 0);

const quaternion = Yuka.Quaternion.lookAt(target, position, up);

详细描述

lookAt() 方法用于创建一个四元数,该四元数可以将向量 position 的位置定向到向量 target 的位置。通常,向量 up 用于控制摄像机在哪个轴向上进行旋转。

注意事项

  • 参数需要是向量对象(Vector3)。
  • 摄像机的正面方向为向量(0, 0, -1)。
  • 可以将返回的四元数对象转换为变换矩阵对象(Matrix4)。