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

toJSON

WanderBehavior的toJSON方法返回一个包含行走行为相关信息的JSON格式对象。

语法

WanderBehavior.toJSON()

返回值

该方法返回一个符合以下规范的JSON格式对象:

{
  "type": "wander",
  "radius": 5,
  "distance": 20,
  "interval": 1000,
  "angleChange": 1
}

其中各字段含义如下:

字段名 类型 含义
type string 行为类型,固定值为"wander"
radius number 行走半径,即在原地转圈时的半径,单位为像素
distance number 随机行走的距离,单位为像素
interval number 两次随机行走的间隔时间,单位为毫秒,即行走速度
angleChange number 每次随机行走的转向角度,单位为度,不能超过180度

示例

const wander = new WanderBehavior();
const json = wander.toJSON();
console.log(json);
// 输出: { "type": "wander", "radius": 5, "distance": 20, "interval": 1000, "angleChange": 1 }

备注

该方法仅适用于WanderBehavior实例,调用其他类型的行为的toJSON方法将会抛出异常。