API reference

ScenePhysicsConstraint Class

Modifiers: open
Represents a physics constraint connecting two physics bodies in a 3D scene.
Constraints limit the relative movement between two bodies. Use the companion object factory methods to create specific constraint types.
Anchors are in the local space of their own body. A hinge, ball-socket, fixed or cone-twist constraint joins the bodies at anchorA: with anchorB at (0, 0, 0), entityB attaches where it is, and any other anchorB is pulled to anchorA. A spring's anchors are its two ends. Axes are in the local space of entityA. The bodies' relative orientation when a constraint is created is its rest pose: limits are measured from it, and a fixed constraint holds it. A constraint without entityB pins entityA to the world where anchorA is when it is created.
Both bodies must exist when a constraint is created. If entityA, or entityB when given, has no physics body yet, the factory logs a warning and returns a constraint whose ScenePhysicsConstraint.handle is 0, which does nothing. The constraint components wait for their bodies instead.
Needs the PhysicsFeature to be enabled to work. Consider using the component-based API (HingeConstraint, BallSocketConstraint, etc.) for ECS-based workflows.
Example of creating a hinge constraint:
val hinge = ScenePhysicsConstraint.createHinge(
    scene = getScene(),
    entityA = doorFrame,
    entityB = door,
    anchorA = Vector3(0.5f, 0f, 0f),
    anchorB = Vector3(-0.5f, 0f, 0f),
    axis = Vector3(0f, 1f, 0f),
    lowerLimit = -1.57f,
    upperLimit = 1.57f
)

Signature

open class ScenePhysicsConstraint

Properties

constraintType : ScenePhysicsConstraint.ConstraintType
[Get]
The type of this constraint.
Signature
val constraintType: ScenePhysicsConstraint.ConstraintType
entityA : Entity?
[Get]
First entity connected by this constraint.
Signature
val entityA: Entity?
entityB : Entity?
[Get]
Second entity connected by this constraint (null = pinned to the world at entityA's anchor).
Signature
val entityB: Entity?
handle : Long
[Get]
Native handle to the constraint.
Signature
var handle: Long

Methods

destroy ()
Destroys this constraint and releases native resources.
Signature
fun destroy()
getAppliedImpulse ()
Gets the impulse currently applied by this constraint.
Useful for detecting stress on the constraint.
Signature
fun getAppliedImpulse(): Float
Returns
Float  Applied impulse magnitude.
isBroken ()
Checks if this constraint has been broken.
Signature
fun isBroken(): Boolean
Returns
Boolean  True if the constraint has exceeded its breaking threshold and is no longer active.
setBreakingThreshold ( force , torque )
Sets the breaking threshold for this constraint.
When the applied impulse exceeds these thresholds, the constraint will break.
Signature
fun setBreakingThreshold(force: Float, torque: Float = 0.0f)
Parameters
force: Float  Maximum force before breaking (Newtons). 0 = unbreakable.
torque: Float  Maximum torque before breaking (Newton-meters). 0 = unbreakable.
setEnabled ( enabled )
Enables or disables this constraint.
Signature
fun setEnabled(enabled: Boolean)
Parameters
enabled: Boolean  Whether the constraint should be active.
setLimits ( lower , upper )
Sets the limits for this constraint.
For hinge: angular limits in radians, lower from -PI to 0 and upper from 0 to PI. For slider: linear limits in meters, lower at most 0 and upper at least 0. Both are measured from where the bodies were when the constraint was created. Other constraint types ignore them.
Signature
fun setLimits(lower: Float, upper: Float)
Parameters
lower: Float  Lower limit.
upper: Float  Upper limit.
setMotor ( enabled , targetVelocity , maxForce )
Configures the motor for this constraint (hinge/slider only).
Signature
fun setMotor(enabled: Boolean, targetVelocity: Float, maxForce: Float)
Parameters
enabled: Boolean  Whether the motor is active.
targetVelocity: Float  Target angular velocity (rad/s) or linear velocity (m/s).
maxForce: Float  Maximum force/torque the motor can apply, at least 0.

Companion Object

Methods

createBallSocket ( scene , entityA , entityB , anchorA , anchorB )
Creates a ball-socket constraint between two entities.
A ball-socket allows rotation in all directions around a point, like a shoulder joint or chain link.
Signature
fun createBallSocket(
    scene: Scene,
    entityA: Entity?,
    entityB: Entity?,
    anchorA: Vector3,
    anchorB: Vector3,
): ScenePhysicsConstraint
Parameters
scene: Scene  The scene containing the physics world.
entityA: Entity?  First physics body (must have Physics component).
entityB: Entity?  Second physics body (null = pinned to the world at entityA's anchor).
anchorA: Vector3  Anchor point in local space of entityA.
anchorB: Vector3  Anchor point in local space of entityB, or (0, 0, 0) to attach entityB where it is.
Returns
ScenePhysicsConstraint  A new ball-socket constraint.
createConeTwist ( scene , entityA , entityB , anchorA , anchorB , twistAxis , swingSpan1 , swingSpan2 , twistSpan , softness , biasFactor , relaxationFactor )
Creates a cone-twist constraint between two entities.
A cone-twist allows rotation within a cone and twist around an axis. Ideal for ragdoll joints like shoulders, hips, and spine.
Signature
fun createConeTwist(
    scene: Scene,
    entityA: Entity?,
    entityB: Entity?,
    anchorA: Vector3,
    anchorB: Vector3,
    twistAxis: Vector3 = Vector3(0f, 1f, 0f),
    swingSpan1: Float = (Math.PI / 2).toFloat(),
    swingSpan2: Float = (Math.PI / 2).toFloat(),
    twistSpan: Float = Math.PI.toFloat(),
    softness: Float = 1.0f,
    biasFactor: Float = 0.3f,
    relaxationFactor: Float = 1.0f,
): ScenePhysicsConstraint
Parameters
scene: Scene  The scene containing the physics world.
entityA: Entity?  First physics body (must have Physics component).
entityB: Entity?  Second physics body (null = pinned to the world at entityA's anchor).
anchorA: Vector3  Anchor point in local space of entityA.
anchorB: Vector3  Anchor point in local space of entityB, or (0, 0, 0) to attach entityB where it is.
twistAxis: Vector3  The primary axis around which twisting occurs.
swingSpan1: Float  Maximum swing on the first axis in radians, from 0 to PI (default: PI/2).
swingSpan2: Float  Maximum swing on the second axis in radians, from 0 to PI (default: PI/2).
twistSpan: Float  Maximum twist angle around twist axis in radians, at least 0 (default: PI).
softness: Float  Constraint softness (0-1, default: 1.0).
biasFactor: Float  Error correction factor (0-1, default: 0.3).
relaxationFactor: Float  Constraint relaxation (0-1, default: 1.0).
Returns
ScenePhysicsConstraint  A new cone-twist constraint.
createFixed ( scene , entityA , entityB , anchorA , anchorB )
Creates a fixed constraint between two entities.
A fixed constraint rigidly connects two bodies with no relative movement. Useful for breakable connections.
Signature
fun createFixed(
    scene: Scene,
    entityA: Entity?,
    entityB: Entity?,
    anchorA: Vector3 = Vector3(0f, 0f, 0f),
    anchorB: Vector3 = Vector3(0f, 0f, 0f),
): ScenePhysicsConstraint
Parameters
scene: Scene  The scene containing the physics world.
entityA: Entity?  First physics body (must have Physics component).
entityB: Entity?  Second physics body (null = pinned to the world at entityA's anchor).
anchorA: Vector3  Anchor point in local space of entityA.
anchorB: Vector3  Anchor point in local space of entityB, or (0, 0, 0) to attach entityB where it is.
Returns
ScenePhysicsConstraint  A new fixed constraint.
createHinge ( scene , entityA , entityB , anchorA , anchorB , axis , lowerLimit , upperLimit )
Creates a hinge constraint between two entities.
A hinge allows rotation around a single axis, like a door hinge or wheel axle.
Signature
fun createHinge(
    scene: Scene,
    entityA: Entity?,
    entityB: Entity?,
    anchorA: Vector3,
    anchorB: Vector3,
    axis: Vector3,
    lowerLimit: Float = -Math.PI.toFloat(),
    upperLimit: Float = Math.PI.toFloat(),
): ScenePhysicsConstraint
Parameters
scene: Scene  The scene containing the physics world.
entityA: Entity?  First physics body (must have Physics component).
entityB: Entity?  Second physics body (null = pinned to the world at entityA's anchor).
anchorA: Vector3  Anchor point in local space of entityA.
anchorB: Vector3  Anchor point in local space of entityB, or (0, 0, 0) to attach entityB where it is.
axis: Vector3  Rotation axis, in the local space of entityA.
lowerLimit: Float  Lower angular limit in radians, from -PI to 0 (default: -PI).
upperLimit: Float  Upper angular limit in radians, from 0 to PI (default: PI).
Returns
ScenePhysicsConstraint  A new hinge constraint.
createSlider ( scene , entityA , entityB , axis , lowerLimit , upperLimit )
Creates a slider constraint between two entities.
A slider allows linear movement along a single axis, like a piston or drawer.
Signature
fun createSlider(
    scene: Scene,
    entityA: Entity?,
    entityB: Entity?,
    axis: Vector3,
    lowerLimit: Float = -1f,
    upperLimit: Float = 1.0f,
): ScenePhysicsConstraint
Parameters
scene: Scene  The scene containing the physics world.
entityA: Entity?  First physics body (must have Physics component).
entityB: Entity?  Second physics body (null = pinned to the world at entityA's anchor).
axis: Vector3  Sliding axis, in the local space of entityA.
lowerLimit: Float  Lower linear limit in meters, at most 0.
upperLimit: Float  Upper linear limit in meters, at least 0.
Returns
ScenePhysicsConstraint  A new slider constraint.
createSpring ( scene , entityA , entityB , anchorA , anchorB , stiffness , damping , restLength )
Creates a spring constraint between two entities.
A spring applies a restoring force between bodies based on their distance.
Signature
fun createSpring(
    scene: Scene,
    entityA: Entity?,
    entityB: Entity?,
    anchorA: Vector3,
    anchorB: Vector3,
    stiffness: Float = 100.0f,
    damping: Float = 1.0f,
    restLength: Float = 0.0f,
): ScenePhysicsConstraint
Parameters
scene: Scene  The scene containing the physics world.
entityA: Entity?  First physics body (must have Physics component).
entityB: Entity?  Second physics body (null = pinned to the world at entityA's anchor).
anchorA: Vector3  Anchor point in local space of entityA.
anchorB: Vector3  Anchor point in local space of entityB.
stiffness: Float  Spring constant (N/m).
damping: Float  Damping coefficient.
restLength: Float  Rest length in meters (0 = use current distance).
Returns
ScenePhysicsConstraint  A new spring constraint.

Inner Enum

ConstraintType Enum

Constraint type enumeration.

Signature

enum ConstraintType : Enum<ScenePhysicsConstraint.ConstraintType> 

Enumeration Constants

MemberDescription
FIXED
Fixed constraint - rigidly connects two bodies with no relative movement.
HINGE
Hinge constraint - allows rotation around a single axis (doors, wheels).
BALL_SOCKET
Ball-socket constraint - allows rotation in all directions around a point (chains).
SLIDER
Slider constraint - allows linear movement along an axis (pistons).
SPRING
Spring constraint - applies spring force between bodies (suspension).
CONE_TWIST
Cone-twist constraint - allows rotation within a cone (ragdoll joints).