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

children

MovingEntity 类的 children 属性是一个数组,包含了所有该实体的子实体,这些子实体的位置是相对于父实体的。子实体可以是任何继承自 MovingEntity 的类的实例。

语法

entity.children

属性

属性 类型 描述
children array 包含子实体的数组

示例

import { MovingEntity } from 'yuka';

class MyEntity extends MovingEntity {
  constructor() {
    super();
    this.addChild(new AnotherEntity());
  }
}

class AnotherEntity extends MovingEntity {
  constructor() {
    super();
  }
}

const entity = new MyEntity();

console.log(entity.children); // 输出 [ AnotherEntity { position: Vector3 { x: 0, y: 0, z: 0 }, ... } ]

在上面的代码中,我们创建了一个 MyEntity 实例,并添加了一个 AnotherEntity 实例作为其子实体。最后,我们打印 entity.children 属性,会输出包含了 AnotherEntity 实例的数组。

备注

请注意,MovingEntity 实例是通过引用来管理其子实体的,因此不要直接操作子实体数组。如果您需要添加、删除或移动子实体,请使用 addChild()removeChild()moveChild() 方法。

参考

  • MovingEntity
  • addChild()
  • removeChild()
  • moveChild()