Class PhysicsCharacterController
Constructors
constructor
-
new PhysicsCharacterController(
position: Vector3,
characterShapeOptions: CharacterShapeOptions,
scene: Scene,
): PhysicsCharacterControllerinstanciate a new characterController
Parameters
- position: Vector3
Initial position
- characterShapeOptions: CharacterShapeOptions
character physics shape options
- scene: Scene
Scene
Returns PhysicsCharacterController
- position: Vector3
Properties
acceleration
Acceleration factor. A value of 1 means reaching max velocity immediately
character Mass
character mass default 0
character Strength
Strength when pushing other bodies default 1e38
dynamic Friction
friction with dynamic surfaces default 1
foot Offset
Distance from the body's position to the character's foot along up.
Used by maxStepHeight to measure how high a contact sits above the foot.
Defaults to half the capsule height passed at construction. Override when
supplying a custom collision shape whose center is not at half-height.
keep Contact Tolerance
maximum distance to keep contact default 0.1
keep Distance
minimum distance to make contact default 0.05
max Acceleration
maximum acceleration in world space coordinate
max Cast Iterations
maximum number of raycast per integration starp default 10
max Character Speed For Solver
character maximum speed default 10
max Slope Cosine
cosine value of slope angle that can be climbed
computed as Math.cos(Math.PI * (angleInDegree / 180.0));
default 0.5 (value for a 60deg angle)
max Step Height
Maximum height the character can automatically step up onto a walkable surface. When greater than 0 the controller enforces this as a strict cap on step climbing, independent of the collision shape's geometry:
- Obstacles whose top is at most maxStepHeight above the character's foot are climbed (either rolled over naturally by the capsule, or snapped up via the step-up sweep when the simplex would otherwise be blocked).
- Obstacles taller than maxStepHeight are blocked, even ones the capsule's rounded bottom would otherwise glide over.
This is enforced by demoting any "walkable" contact that sits more than
maxStepHeight above the foot into an extra horizontal wall constraint, so the
step-height limit does not depend on the capsule radius. As a documented side
effect, slopes whose contact rises above maxStepHeight (roughly when
capsuleRadius * (1 - cos(slopeAngle)) > maxStepHeight) are also treated as
walls. Pick maxStepHeight large enough to clear the slope angles you want to
remain walkable, or rely on maxSlopeCosine alone (with maxStepHeight = 0)
when the rounded-capsule riding behavior is acceptable.
Step-up only triggers against STATIC and ANIMATED bodies. Dynamic bodies fall through to normal contact resolution and pushing behavior.
Thin walls / fences with floor behind them are not considered steppable: the
landing must be measurably higher than the starting position along up.
The foot is computed as position - up * footOffset. Override footOffset if
you supply a custom collision shape whose center is not at half-height.
Assumes up is a unit vector.
default 0 (disabled)
on Trigger Collision Observable
Observable for trigger entered and trigger exited events
penetration Recovery Speed
speed when recovery from penetration default 1.0
static Friction
friction with static surfaces default 0
up
up vector
Accessors
shape
-
Get shape used for collision
Returns PhysicsShape
shape Options
-
Get the shape options used to build the collision shape
Returns CharacterShapeOptions
Methods
calculate Movement
-
calculateMovement(
deltaTime: number,
forwardWorld: Vector3,
surfaceNormal: Vector3,
currentVelocity: Vector3,
surfaceVelocity: Vector3,
desiredVelocity: Vector3,
upWorld: Vector3,
): Vector3Helper function to calculate velocity based on surface informations and current velocity state and target
Parameters
- deltaTime: number
frame delta time in seconds. When using scene.deltaTime divide by 1000.0
- forwardWorld: Vector3
character forward in world coordinates
- surfaceNormal: Vector3
surface normal direction
- currentVelocity: Vector3
current velocity
- surfaceVelocity: Vector3
velocity induced by the surface
- desiredVelocity: Vector3
desired character velocity
- upWorld: Vector3
up vector in world space
Returns Vector3
a new velocity vector
- deltaTime: number
calculate Movement To Ref
-
calculateMovementToRef(
deltaTime: number,
forwardWorld: Vector3,
surfaceNormal: Vector3,
currentVelocity: Vector3,
surfaceVelocity: Vector3,
desiredVelocity: Vector3,
upWorld: Vector3,
result: Vector3,
): booleanHelper function to calculate velocity based on surface informations and current velocity state and target
Parameters
- deltaTime: number
frame delta time in seconds. When using scene.deltaTime divide by 1000.0
- forwardWorld: Vector3
character forward in world coordinates
- surfaceNormal: Vector3
surface normal direction
- currentVelocity: Vector3
current velocity
- surfaceVelocity: Vector3
velocity induced by the surface
- desiredVelocity: Vector3
desired character velocity
- upWorld: Vector3
up vector in world space
- result: Vector3
resulting velocity vector
Returns boolean
boolean true if result has been computed
- deltaTime: number
check Support
-
Compute a CharacterSurfaceInfo from current state and a direction
Parameters
- deltaTime: number
frame delta time in seconds. When using scene.deltaTime divide by 1000.0
- direction: Vector3
direction to check, usually gravity direction
Returns CharacterSurfaceInfo
a CharacterSurfaceInfo object
- deltaTime: number
check Support To Ref
-
Compute a CharacterSurfaceInfo from current state and a direction
Parameters
- deltaTime: number
frame delta time in seconds. When using scene.deltaTime divide by 1000.0
- direction: Vector3
direction to check, usually gravity direction
- surfaceInfo: CharacterSurfaceInfo
output for surface info
Returns void
- deltaTime: number
dispose
-
Dispose the character controller
Returns void
get Position
get Velocity
integrate
-
Update internal state. Must be called once per frame
Parameters
- deltaTime: number
frame delta time in seconds. When using scene.deltaTime divide by 1000.0
- surfaceInfo: CharacterSurfaceInfo
surface information returned by checkSupport
- gravity: Vector3
gravity applied to the character. Can be different that world gravity
Returns void
- deltaTime: number
move With Collisions
-
Move the character with collisions
Parameters
- displacement: Vector3
defines the requested displacement vector
Returns void
- displacement: Vector3
set Position
set Shape Options
-
setShapeOptions(
characterShapeOptions: CharacterShapeOptions,
preserveFootPosition?: boolean,
): voidSet new shape options and rebuild the collision shape accordingly. When the options provide an explicit
shape, it is used directly; otherwise a capsule is created from thecapsuleHeight/capsuleRadiusvalues. The resulting shape is assigned through the shape setter, which releases the previously owned shape.Parameters
- characterShapeOptions: CharacterShapeOptions
character physics shape options
- preserveFootPosition: boolean = true
when true (default), the controller position is adapted so the world-space foot position (center - up * footOffset) is kept fixed as the height changes; when false, the position is left unchanged.
Returns void
- characterShapeOptions: CharacterShapeOptions
Character controller using physics