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

getWorldDirection

描述

getWorldDirection() 方法可以返回当前对象的朝向,即该对象在世界坐标系中的方向。该方向是以向量形式返回的,并可用于将该方向应用于其他计算中。

语法

getWorldDirection(optionalTarget)
  • 参数:
    • optionalTarget:(Vector3) 可选参数。一个向量,用于存储返回的世界方向。如果不指定,该方法会创建一个新的向量并将其返回。

示例

var myObject = new THREE.Object3D();
myObject.position.set(10, 20, 30);
myObject.lookAt(0, 0, 0);

var worldDirection = new THREE.Vector3();
myObject.getWorldDirection(worldDirection);

console.log(worldDirection); // 输出:THREE.Vector3(-0.2672612419124244, -0.5345224838248488, -0.8017837257372732)

返回值

该方法返回一个Vector3对象,表示当前对象在世界坐标系中的朝向。若指定了optionalTarget参数,则该对象会被修改并返回;否则,会新创建一个Vector3对象并返回。

注意事项

  • 要获取对象在其自身坐标系中的朝向,请使用Object3D.rotation属性。
  • 如果在调用该方法之前对象未进行过任何旋转,则结果向量与对象的默认朝向相同:即x轴正方向。

参考