API reference
API reference
Select your platform
No SDKs available
No versions available

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.
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 = world anchor).
Signature
val entityB: Entity?
handle : Long
[Get]
Native handle to the constraint.
Signature
var handle: Long

Functions

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. For slider: linear limits in meters.
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.

Companion Object

Companion Object Functions

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 = world anchor).
anchorA: Vector3
  Anchor point in local space of entityA.
anchorB: Vector3
  Anchor point in local space of entityB.
Returns
  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 = world anchor).
anchorA: Vector3
  Anchor point in local space of entityA.
anchorB: Vector3
  Anchor point in local space of entityB.
twistAxis: Vector3
  The primary axis around which twisting occurs.
swingSpan1: Float
  Maximum swing angle on first axis in radians (default: PI/2).
swingSpan2: Float
  Maximum swing angle on second axis in radians (default: PI/2).
twistSpan: Float
  Maximum twist angle around twist axis in radians (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
  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 = world anchor).
anchorA: Vector3
  Anchor point in local space of entityA.
anchorB: Vector3
  Anchor point in local space of entityB.
Returns
  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 = world anchor).
anchorA: Vector3
  Anchor point in local space of entityA.
anchorB: Vector3
  Anchor point in local space of entityB.
axis: Vector3
  Rotation axis (in world space).
lowerLimit: Float
  Lower angular limit in radians (default: -PI).
upperLimit: Float
  Upper angular limit in radians (default: PI).
Returns
  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 = world anchor).
axis: Vector3
  Sliding axis (in world space).
lowerLimit: Float
  Lower linear limit in meters.
upperLimit: Float
  Upper linear limit in meters.
Returns
  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 = world 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
  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).
Did you find this page helpful?