Documentation / scene / FloatingBody
Class: FloatingBody
Defined in: libs/scene/src/utility/buoyancy.ts:235
A rigid body that floats on a water surface, with its own integrator.
For applications without a physics library. The motion is force driven: the body owns a position, an orientation and their velocities, and the water only ever applies the force and torque a BuoyancyVolume computes. That is what makes a hull behave like a hull - it has mass, so it lags the surface, overshoots into it and rolls back, instead of sliding along a height field.
Semi-implicit Euler at a fixed step, box inertia kept as a diagonal in body axes, quaternion orientation renormalised every step. Water resistance is a per-second fraction of velocity, blended between the air and water values by how much of the body is under, so a body launched clear of the water keeps its speed until it lands. No collision.
Constructors
Constructor
new FloatingBody(
options):FloatingBody
Defined in: libs/scene/src/utility/buoyancy.ts:271
Creates a floating body.
Parameters
options
Returns
FloatingBody
Properties
volume
readonlyvolume:BuoyancyVolume
Defined in: libs/scene/src/utility/buoyancy.ts:237
The hull's buoyancy.
node
node:
SceneNode
Defined in: libs/scene/src/utility/buoyancy.ts:239
Node driven by the body, if any.
linearDamping
linearDamping:
number
Defined in: libs/scene/src/utility/buoyancy.ts:241
Fraction of linear velocity shed per second in water.
angularDamping
angularDamping:
number
Defined in: libs/scene/src/utility/buoyancy.ts:243
Fraction of angular velocity shed per second in water.
airLinearDamping
airLinearDamping:
number
Defined in: libs/scene/src/utility/buoyancy.ts:245
Fraction of linear velocity shed per second in air.
airAngularDamping
airAngularDamping:
number
Defined in: libs/scene/src/utility/buoyancy.ts:247
Fraction of angular velocity shed per second in air.
position
readonlyposition:Vector3
Defined in: libs/scene/src/utility/buoyancy.ts:249
World position of the hull's centre.
rotation
readonlyrotation:Quaternion
Defined in: libs/scene/src/utility/buoyancy.ts:251
World orientation.
velocity
readonlyvelocity:Vector3
Defined in: libs/scene/src/utility/buoyancy.ts:253
Linear velocity in metres per second.
angularVelocity
readonlyangularVelocity:Vector3
Defined in: libs/scene/src/utility/buoyancy.ts:255
Angular velocity in radians per second, world axes.
externalForce
readonlyexternalForce:Vector3
Defined in: libs/scene/src/utility/buoyancy.ts:257
Extra force applied at the centre of mass on the next step, in newtons. Cleared after each frame.
externalTorque
readonlyexternalTorque:Vector3
Defined in: libs/scene/src/utility/buoyancy.ts:259
Extra torque applied on the next step, in newton-metres. Cleared after each frame.
Accessors
mass
Get Signature
get mass():
number
Defined in: libs/scene/src/utility/buoyancy.ts:308
Mass in kilograms.
Returns
number
Methods
reset()
reset(
x,z,waterLevel?,yaw?):void
Defined in: libs/scene/src/utility/buoyancy.ts:318
Place the body at rest on a still surface and clear its velocities.
Parameters
x
number
World X.
z
number
World Z.
waterLevel?
number = 0
Still-water level the body should float on.
yaw?
number = 0
Heading in radians about world Y.
Returns
void
update()
update(
deltaSeconds,waveHeight,waterLevel):void
Defined in: libs/scene/src/utility/buoyancy.ts:332
Integrate one frame.
Parameters
deltaSeconds
number
Frame delta in seconds.
waveHeight
Surface height above the still-water level at a world XZ.
waterLevel
number
World Y of the still-water level.
Returns
void
step()
step(
dt,waveHeight,waterLevel):void
Defined in: libs/scene/src/utility/buoyancy.ts:355
Advance the body by one fixed step.
Parameters
dt
number
Step in seconds.
waveHeight
Surface height above the still-water level at a world XZ.
waterLevel
number
World Y of the still-water level.
Returns
void
applyToNode()
applyToNode():
void
Defined in: libs/scene/src/utility/buoyancy.ts:405
Write the pose to the node, if there is one.
Returns
void