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

clampMovement

功能介绍

clampMovement()方法用于将对象的移动位置限制在指定的 NavMesh 区域内。

语法

clampMovement(mesh, object, offset);

参数说明

  • mesh:NavMesh对象,表示所有可移动区域的虚拟网格。
  • object:被移动的对象。
  • offset:相对于被移动的对象的位置偏移量。

返回值

无返回值。

其他说明

  • 当被移动的对象的位置不在 NavMesh 区域内时,clampMovement() 方法会按照 NavMesh 的边界限制对象的移动。

示例

var mesh = new NavMesh();
var object = new THREE.Mesh(geometry, material);
var offset = new THREE.Vector3(0, 10, 0);

// 将对象绑定到 NavMesh
mesh.addObject(object);

// 移动对象,并限制在 NavMesh 区域内
object.position.add(new THREE.Vector3(10, -20, 5));
clampMovement(mesh, object, offset);

注意事项

  • 在调用 clampMovement() 方法前,需要先将对象绑定到 NavMesh 中。
  • 确保 NavMesh 区域正确设置,否则对象可能无法正确限制在指定区域内。