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

neighbors

简介

MovingEntity(运动实体)是Yuka.js库中的一个概念,代表具有位置和运动能力的实体。neighbors是MovingEntity类的一个方法,用于查询与当前实体在给定距离内的邻居实体。

语法

MovingEntity.neighbors( radius, entities )

参数

  • radius:Number类型,表示查询半径,单位为距离单位(例如像素)。
  • entities:Array类型,当做查询的邻居实体数组。

返回

返回类型为Array,包含在给定半径内的邻居实体。

示例

import { MovingEntity } from 'yuka';

// 创建实体数组
const numEntities = 10;
const entities = [];
for  ( let i = 0; i < numEntities; i ++ ) {
    entities.push( new MovingEntity() );
}

// 查询当前实体的邻居
const entity = new MovingEntity();
const neighbors = entity.neighbors( 10, entities );
console.log( neighbors ); // [ MovingEntity, MovingEntity, ... ]

注释

  • 查询半径越小,查询速度越快。
  • 返回的邻居实体数组不包括当前实体。
  • 在查询之前,必须确保所有实体的位置和速度属性都已经被正确设置。