API reference

Physics Function

Secondary constructor for creating a Physics component with explicit parameters. Provides a more convenient way to instantiate Physics components than using the primary constructor.

Signature

fun Physics(
    shape: String,
    linearVelocity: Vector3 = Vector3(0.0f),
    angularVelocity: Vector3 = Vector3(0.0f),
    dimensions: Vector3 = Vector3(0.5f),
    density: Float = 1.0f,
    restitution: Float = 0.2f,
    friction: FrictionObject = FrictionObject(0.5f, 0f, 0f),
    state: PhysicsState = PhysicsState.DYNAMIC,
    applyForce: Vector3 = Vector3(0.0f),
    linearDamping: Float = 0.05f,
    angularDamping: Float = 0.05f,
    allowSleeping: Boolean = true,
): Physics

Parameters

shape: String Primitive name ("box", "sphere", "cylinderX", "cylinderY" or "cylinderZ"), or URL or path to the collision shape file (GLTF/GLB format)
linearVelocity: Vector3 Initial linear velocity vector. Defaults to zero.
angularVelocity: Vector3 Initial angular velocity vector. Defaults to zero.
dimensions: Vector3 Size of a primitive shape in meters: half the width, height and depth of a box, the radius of a sphere in x, and the radius in x and full height in y of a cylinder. Defaults to (0.5, 0.5, 0.5), a 1 m box.
density: Float Mass density of the object in kg/m³. For a shape other than a box or sphere, it's the mass in kg. Defaults to 1.0.
restitution: Float Bounciness coefficient (0.0 = no bounce, 1.0 = perfect bounce). Defaults to 0.2.
friction: FrictionObject Friction properties. Only sliding friction has an effect. Defaults to sliding=0.5.
state: PhysicsState Physics state (STATIC, DYNAMIC, or KINEMATIC). Defaults to DYNAMIC.
applyForce: Vector3 Impulse to apply once at the next physics step, in newton-seconds. Defaults to zero.
linearDamping: Float How fast the object's movement slows by itself, as a rate per second. Defaults to 0.05.
angularDamping: Float How fast the object's spin slows by itself, as a rate per second. Defaults to 0.05.
allowSleeping: Boolean Whether the body may fall asleep once it has been nearly still for a while. Defaults to true.

Returns

Physics A configured Physics component instance