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

distanceTo

简介

distanceTo 方法用于计算当前向量与另一个向量之间的距离。

语法

distanceTo(v: Vector3): number

参数

  • v:类型为 Vector3,表示另一个向量对象。

返回值

返回当前向量与另一个向量之间的距离,类型为 number

示例

const v1 = new Vector3(1, 2, 3);
const v2 = new Vector3(4, 5, 6);
const distance = v1.distanceTo(v2);
console.log(distance); // 输出 5.196152422706632

注意事项

  • v 参数必须是一个 Vector3 对象,否则会导致方法调用失败。
  • distanceTo 方法计算的是两个向量之间的空间欧几里得距离,使用时应注意计算结果和实际物理距离的差异。
  • distanceTo 方法不会改变当前向量或传入的向量,仅用于计算距离,并返回计算结果。