Skip to main content

BodyComponent

Class

Allows Physics simulation to control SceneObject.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Since Lens Scripting v164

Index

Remarks

Derived from ColliderComponent, attaching this to a SceneObject turns it into a dynamic rigid-body that is automatically moved by the physics simulation in response to gravity, collisions, and other forces.

Example

// @input Physics.BodyComponent bodyComponent

// Add instant impulse force upward
script.bodyComponent.addForce(new vec3(0, 500, 0), Physics.ForceMode.Impulse);

// Add instant impulse torque to rotate the object
script.bodyComponent.addTorque(new vec3(0, 0, Math.PI * -25), Physics.ForceMode.Impulse);

// Every frame, add upward force over time, relative to the object rotation
// This is similar to a rocket boosting the object upward
script.createEvent("UpdateEvent").bind(function() {
script.bodyComponent.addRelativeForce(new vec3(0, 2000, 0), Physics.ForceMode.Force);
});

Extends

Properties

angularDamping

angularDamping: number

Damping applied to angular velocity, in the range 0.0 (no damping) to 1.0 (maximum damping).

Since

Lens Scripting Version 164

Default Value

0

angularVelocity

angularVelocity: vec3

Angular velocity, expressed as an axis of rotation scaled by angular speed (radians/s).

Since

Lens Scripting Version 164

Default Value

(0, 0, 0)

Inherited from

ColliderComponent.angularVelocity


damping

damping: number

Damping applied to linear velocity, in the range 0.0 (no damping) to 1.0 (maximum damping). This produces an effect similar to drag in that it causes the object to slow down over time. It is not however physically accurate, and it doesn't take into account surface area or mass.

Since

Lens Scripting Version 164

Default Value

0

debugDrawEnabled

debugDrawEnabled: boolean

Toggle collider wire rendering for visualizing collider geometry shape and where it is placed.

Since

Lens Scripting Version 152

Default Value

false

Inherited from

ColliderComponent.debugDrawEnabled


density

density: number

Density (kg/L) of the object, used to derive mass from volume. If modified, mass changes according to shape and scale.

Since

Lens Scripting Version 164


dynamic

dynamic: boolean

If enabled, the body is dynamically simulated, such that it responds to forces and collisions, nested collider/body components will be merged into compound shapes. Otherwise, it acts as a static collider, functionally equivalent to Physics.ColliderComponent.

Since

Lens Scripting Version 164

Default Value

true

enabled

enabled: boolean

If disabled, the Component will stop enacting its behavior.

Default Value

true

Inherited from

ColliderComponent.enabled


excludeFromParentCompounding

excludeFromParentCompounding: boolean

If enabled, this collider is never merged into an ancestor's compound shape; it always becomes its own top-level collider simulated with its own settings.

Remarks

This toggle is independent of ColliderComponent#forceCompound: it only controls whether this collider joins an ancestor's compound, and it does not change whether this collider aggregates its own descendants. That remains governed by ColliderComponent#forceCompound or being a dynamic body. Splitting out of a compound does not suppress collisions with the former compound. Whether the two collide is governed by the normal collision-filtering rules, subject to their SceneObject#layer, ColliderComponent#filter, and ColliderComponent#intangible settings.

Since

Lens Scripting Version 378

Default Value

false

Example

// Keep an oversized interaction-only trigger out of its parent body's compound shape
// @input Physics.ColliderComponent triggerCollider
script.triggerCollider.excludeFromParentCompounding = true;
script.triggerCollider.intangible = true;

Inherited from

ColliderComponent.excludeFromParentCompounding


filter

filter: Filter

Collision filter to use for this collider.

Since

Lens Scripting Version 183

Default Value

null

Inherited from

ColliderComponent.filter


fitVisual

fitVisual: boolean

If enabled, the collider shape extends to fit the visual mesh, if any. Only applicable for Box and Sphere shapes.

Since

Lens Scripting Version 164

Default Value

true

Inherited from

ColliderComponent.fitVisual


forceCompound

forceCompound: boolean

Nested collider/body components may be merged into compound shapes. By default, this occurs only for dynamic bodies and not for static colliders. If forceCompound is set, this occurs for static colliders as well.

Since

Lens Scripting Version 169

Default Value

false

Inherited from

ColliderComponent.forceCompound


intangible

intangible: boolean

If enabled, the collider doesn't interact with the world but may still be detected with ray casts and intersection events.

Since

Lens Scripting Version 164

Default Value

false

Inherited from

ColliderComponent.intangible


isBeingDestroyed

readonly isBeingDestroyed: boolean

Returns true if this Component is currently being destroyed. Becomes true as soon as destruction begins via Component#destroy or destruction of its owning SceneObject, before any OnDestroyEvent callbacks fire.

Since

Lens Scripting Version 364

Example

if (!script.isBeingDestroyed) {
// Component is still fully alive
}

Inherited from

ColliderComponent.isBeingDestroyed


isEnabledInHierarchy

readonly isEnabledInHierarchy: boolean

Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.

Inherited from

ColliderComponent.isEnabledInHierarchy


mass

mass: number

Mass (kg) of the object. If modified from this field, mass is constant irrespective of shape and scale.

Since

Lens Scripting Version 164


matter

matter: Matter

The matter used by the collider to define its physical substance, such as friction and bounciness.

Since

Lens Scripting Version 169

Default Value

null

Inherited from

ColliderComponent.matter


onCollisionEnter

readonly onCollisionEnter: event1<CollisionEnterEventArgs, void>

Signals when objects initially collide.

Since

Lens Scripting Version 152

Inherited from

ColliderComponent.onCollisionEnter


onCollisionExit

readonly onCollisionExit: event1<CollisionExitEventArgs, void>

Signals when objects stop colliding.

Since

Lens Scripting Version 152

Inherited from

ColliderComponent.onCollisionExit


onCollisionStay

readonly onCollisionStay: event1<CollisionStayEventArgs, void>

Signals every frame while objects continue to collide.

Since

Lens Scripting Version 152

Inherited from

ColliderComponent.onCollisionStay


onOverlapEnter

readonly onOverlapEnter: event1<OverlapEnterEventArgs, void>

Signals when colliders first overlap.

Since

Lens Scripting Version 152

Inherited from

ColliderComponent.onOverlapEnter


onOverlapExit

readonly onOverlapExit: event1<OverlapExitEventArgs, void>

Signals when colliders stop overlapping.

Since

Lens Scripting Version 152

Inherited from

ColliderComponent.onOverlapExit


onOverlapStay

readonly onOverlapStay: event1<OverlapStayEventArgs, void>

Signals every frame while colliders continue to overlap.

Since

Lens Scripting Version 152

Inherited from

ColliderComponent.onOverlapStay


overlapFilter

overlapFilter: Filter

Collision filter used for overlap events.

Since

Lens Scripting Version 164

Default Value

null

Inherited from

ColliderComponent.overlapFilter


rotateSmoothFactor

rotateSmoothFactor: number

Smoothing spring factor, for rotation.

Since

Lens Scripting Version 169

Default Value

30

Inherited from

ColliderComponent.rotateSmoothFactor


sceneObject

readonly sceneObject: SceneObject

The SceneObject this component is on.

Inherited from

ColliderComponent.sceneObject


shape

shape: Shape

The Shape object used for collision.

Since

Lens Scripting Version 157

Default Value

null

Inherited from

ColliderComponent.shape


smooth

smooth: boolean

Smooth transform changes using a dampened spring. Useful to reduce motion noise. This only applies to the simulation and changes from outside the simulation. The SceneObject's transform is not affected. It has no effect for dynamic bodies.

Since

Lens Scripting Version 169

Default Value

false

Inherited from

ColliderComponent.smooth


translateSmoothFactor

translateSmoothFactor: number

Smoothing spring factor, for translation. This controls the restitution strength of the spring, so low values are smoother but lag more.

Since

Lens Scripting Version 169

Default Value

30

Inherited from

ColliderComponent.translateSmoothFactor


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

ColliderComponent.uniqueIdentifier


velocity

velocity: vec3

Linear velocity (cm/s).

Since

Lens Scripting Version 164

Default Value

(0, 0, 0)

Inherited from

ColliderComponent.velocity


worldSettings

worldSettings: WorldSettingsAsset

The WorldSettingsAsset used by the collider to define the physics simulation settings.

Since

Lens Scripting Version 169

Default Value

null

Inherited from

ColliderComponent.worldSettings

Methods

addForce()

addForce(force, mode): void

Apply linear force at the object's center-of-mass.

Parameters

ParameterType
forcevec3
modeForceMode

Returns

void

Since

Lens Scripting Version 164


addForceAt()

addForceAt(force, offset, mode): void

Apply force at a point offset from the object's origin, effectively generating torque.

Parameters

ParameterType
forcevec3
offsetvec3
modeForceMode

Returns

void

Since

Lens Scripting Version 164


addPointConstraint()

addPointConstraint(target, position): ConstraintComponent

Add a point constraint between this body and the given collider, at the given position. target is optional. If null, it is statically constrained to the world. This is a convenience function that creates a child SceneObject with a ConstraintComponent, and sets its type, target, and constraint parameters. To fully remove the constraint, its SceneObject must be removed - not the component. Call removeConstraint() to do this.

Parameters

ParameterType
targetColliderComponent
positionvec3

Returns

ConstraintComponent

Since

Lens Scripting Version 164


addRelativeForce()

addRelativeForce(force, mode): void

Relative to local rotation, apply linear force at the object's center-of-mass.

Parameters

ParameterType
forcevec3
modeForceMode

Returns

void

Since

Lens Scripting Version 164


addRelativeForceAt()

addRelativeForceAt(force, position, mode): void

Relative to local rotation, apply force at a point offset from the object's origin, effectively generating torque.

Parameters

ParameterType
forcevec3
positionvec3
modeForceMode

Returns

void

Since

Lens Scripting Version 164


addRelativeTorque()

addRelativeTorque(torque, mode): void

Relative to local rotation, apply torque (angular force).

Parameters

ParameterType
torquevec3
modeForceMode

Returns

void

Since

Lens Scripting Version 164


addTorque()

addTorque(torque, mode): void

Apply torque (angular force).

Parameters

ParameterType
torquevec3
modeForceMode

Returns

void

Since

Lens Scripting Version 164


clearMotion()

clearMotion(): void

Clears all velocities and forces on a collider.

Returns

void

Since

Lens Scripting Version 164

Inherited from

ColliderComponent.clearMotion


destroy()

destroy(): void

Destroys the component.

Returns

void

Inherited from

ColliderComponent.destroy


getSceneObject()

getSceneObject(): SceneObject

Returns the SceneObject the component is attached to.

Returns

SceneObject

Inherited from

ColliderComponent.getSceneObject


getTransform()

getTransform(): Transform

Returns the Transform this component is attached to.

Returns

Transform

Inherited from

ColliderComponent.getTransform


getTypeName()

static getTypeName(): TypeName<BodyComponent>

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<BodyComponent>

Since

Lens Scripting Version 164

Overrides

ColliderComponent.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ColliderComponent.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ColliderComponent.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ColliderComponent.isSame


removeConstraint()

removeConstraint(constraint): void

Removes a constraint that was added with one of the add*Constraint() functions.

Parameters

ParameterType
constraintConstraintComponent

Returns

void

Since

Lens Scripting Version 164

See also