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

weight

介绍

weight 是 Yuka js 库中的一个 Behavior。该 Behavior 用于处理实体的重量信息。

API

constructor(value = 1)

  • 参数:
    • value:重量的初始值,默认为 1。
  • 返回值:新创建的 weight 实例。

例子

import { weight } from 'yuka';

const entityWeight = new weight(5);

setValue(value)

设置实体的重量。

  • 参数:
    • value:重量的新值。
  • 返回值:无。

例子

entityWeight.setValue(8);

getValue()

获取实体的当前重量。

  • 参数:无。
  • 返回值:实体的当前重量。

例子

const currentWeight = entityWeight.getValue();

add(value)

增加实体的重量。

  • 参数:
    • value:要添加的重量值。
  • 返回值:无。

例子

entityWeight.add(3);

subtract(value)

减少实体的重量。

  • 参数:
    • value:要减少的重量值。
  • 返回值:无。

例子

entityWeight.subtract(2);

示例

import { weight } from 'yuka';

const entityWeight = new weight(5);

console.log(entityWeight.getValue()); // 输出:5

entityWeight.add(3);

console.log(entityWeight.getValue()); // 输出:8

entityWeight.subtract(2);

console.log(entityWeight.getValue()); // 输出:6