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

addSubgoal

该方法用于向合成目标(Composite Goal)添加子目标(Subgoal)。

语法

compositeGoal.addSubgoal(subgoal)

参数

  • subgoal:必需,类型为 Goal,表示要添加的子目标。

描述

合成目标(Composite Goal)是由多个子目标(Subgoal)组成的目标。addSubgoal 方法用于向合成目标中添加子目标。添加的子目标可以是任何类型的目标,包括行为(Atomic Goal)和其他的合成目标。

示例

// 创建一个合成目标
const compositeGoal = new CompositeGoal();

// 创建一个行为目标
const atomicGoal = new AtomicGoal();

// 向合成目标中添加行为目标
compositeGoal.addSubgoal(atomicGoal);

// 创建另一个合成目标
const anotherCompositeGoal = new CompositeGoal();

// 向第一个合成目标中添加第二个合成目标
compositeGoal.addSubgoal(anotherCompositeGoal);

异常

如果传入的 subgoal 参数为 nullundefined,则该方法会抛出异常。