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

ScenePhysicsObject Class

Modifiers: open
Represents a physics-enabled object in a 3D scene. Can be used to create custom physics implementations using the ECS.
Needs the PhysicsFeature to be enabled to work. Consider using the Physics component before implementing a custom physics system.
Example of a Custom Physics System, which creates a Physics box with initial linear velocity specified by the CustomPhysics component.
Component:
<?xml version="1.0" ?>
<ComponentSchema packageName="com.meta.aether.apps.experiments.physics">
 <Component name="CustomPhysics">
   <Vector3Attribute
     name="initialLinearVelocity"
     defaultValue="0.0f, 0.0f, 0.0f"
   />
 </Component>
</ComponentSchema>

System:
class CustomPhysicsSystem() : SystemBase() {
private val physicsObjects_ = HashMap<Entity, ScenePhysicsObject>()
override fun execute() {
  val q = Query.where { changed(CustomPhysics.id) and has(Transform.id) }
  for (ent in q.eval()) {
    if (physicsObjects_.containsKey(ent)) {
      continue
    }
    val physics = ScenePhysicsObject.createBox(getScene(), ent, 0.25f, 0.25f, 0.25f, 0.5f)
    physicsObjects_.put(ent, physics)
    physics.setPose(ent.getComponent<Transform>().transform)
    physics.setLinearVelocity(ent.getComponent<CustomPhysics>().initialLinearVelocity)
    Log.i("Physics", "Created physics object for entity $ent $physics")
  }
}
override fun delete(entity: Entity) {
  if (physicsObjects_.containsKey(entity)) {
    physicsObjects_[entity]?.destroy()
    physicsObjects_.remove(entity)
  }
}

Signature

open class ScenePhysicsObject

Properties

entity : Entity?
[Get]
Signature
val entity: Entity?
handle : Long
[Get]
Native handle to the physics object.
Signature
var handle: Long

Functions

applyForce ( force )
Applies a force to this physics object
Signature
fun applyForce(force: Vector3)
Parameters
force: Vector3
  The force vector to apply (in newtons)
applyForceAtRelativePosition ( force , relativePos )
Applies a force to this physics object at a specified position relative to its center.
This can create both linear and angular acceleration depending on the force and position.
Signature
fun applyForceAtRelativePosition(force: Vector3, relativePos: Vector3)
Parameters
force: Vector3
  The force vector to apply (in newtons)
relativePos: Vector3
  The position relative to the center of mass where the force is applied
applyTorque ( torqueX , torqueY , torqueZ )
Applies a torque (rotational force) to this physics object.
Signature
fun applyTorque(torqueX: Float, torqueY: Float, torqueZ: Float)
Parameters
torqueX: Float
  The X component of the torque vector
torqueY: Float
  The Y component of the torque vector
torqueZ: Float
  The Z component of the torque vector
destroy ()
Signature
fun destroy()
getPose ()
Gets the current position and rotation of this physics object.
Signature
fun getPose(): Pose
Returns
  The current pose
setAngularVelocity ( angularVelocity )
Sets the angular velocity of this physics object.
Signature
fun setAngularVelocity(angularVelocity: Vector3)
Parameters
angularVelocity: Vector3
  The angular velocity vector (in radians per second)
setBodyType ( bodyType , mass )
Sets the body type (STATIC, DYNAMIC, or KINEMATIC) of this physics object.
Signature
fun setBodyType(bodyType: PhysicsState, mass: Float)
Parameters
bodyType: PhysicsState
  The physics state (0 = STATIC, 1 = DYNAMIC, 2 = KINEMATIC)
mass: Float
  The mass for dynamic bodies (ignored for static/kinematic)
setDamping ( linearDamping , angularDamping )
Sets the linear and angular damping for this physics object.
Damping reduces velocity over time, simulating air resistance or friction. Higher values cause faster velocity decay.
Signature
fun setDamping(linearDamping: Float = 0.05f, angularDamping: Float = 0.85f)
Parameters
linearDamping: Float
  Linear velocity damping (0.0 = no damping, 1.0 = full damping). Default: 0.05
angularDamping: Float
  Angular velocity damping (0.0 = no damping, 1.0 = full damping). Default: 0.85
setDeactivationTime ( time )
Sets the deactivation time for this physics object.
When a physics body comes to rest (below sleeping thresholds), it will deactivate after this amount of time to save CPU resources.
Signature
fun setDeactivationTime(time: Float = 0.8f)
Parameters
time: Float
  Time in seconds before deactivation. Default: 0.8
setFriction ( friction , rolling , spinning )
Sets the friction properties of this physics object.
Signature
fun setFriction(friction: Float, rolling: Float = friction, spinning: Float)
Parameters
friction: Float
  The surface friction coefficient
rolling: Float
  The rolling friction coefficient (defaults to the same as surface friction)
spinning: Float
  The spinning friction coefficient
setLinearVelocity ( velocity )
Sets the linear velocity of this physics object.
Signature
fun setLinearVelocity(velocity: Vector3)
Parameters
velocity: Vector3
  The linear velocity vector (in meters per second)
setPose ( pose )
Sets the position and rotation of this physics object.
Signature
fun setPose(pose: Pose)
Parameters
pose: Pose
  The position and rotation to set
setRestitution ( restitution )
Sets the restitution (bounciness) of this physics object.
Signature
fun setRestitution(restitution: Float)
Parameters
restitution: Float
  The restitution value (0.0 = no bounce)
setSleepingThresholds ( linear , angular )
Sets the sleeping thresholds for this physics object.
When linear and angular velocities fall below these thresholds, the body begins the deactivation countdown. Lower values keep bodies active longer.
Signature
fun setSleepingThresholds(linear: Float = 1.6f, angular: Float = 2.5f)
Parameters
linear: Float
  Linear velocity threshold in m/s. Default: 1.6
angular: Float
  Angular velocity threshold in rad/s. Default: 2.5

Companion Object

Companion Object Functions

createBox ( scene , entity , width , height , depth , mass )
Creates a box-shaped physics object.
Signature
fun createBox(scene: Scene, entity: Entity?, width: Float, height: Float, depth: Float, mass: Float): ScenePhysicsObject
Parameters
scene: Scene
  The scene in which to create the physics object
entity: Entity?
  Optional entity to associate with this physics object
width: Float
  Width of the box in meters
height: Float
  Height of the box in meters
depth: Float
  Depth of the box in meters
mass: Float
  Mass of the box in kilograms (0 for static objects)
Returns
  A new box-shaped physics object
createFromCollider ( scene , entity , collider , mass )
Creates a physics object using an existing collider.
This allows multiple physics objects to share the same collision shape, reducing memory usage when many objects have the same geometry.
Signature
fun createFromCollider(scene: Scene, entity: Entity?, collider: ScenePhysicsCollider, mass: Float): ScenePhysicsObject
Parameters
scene: Scene
  The scene in which to create the physics object
entity: Entity?
  Optional entity to associate with this physics object
  The collider defining the collision shape
mass: Float
  Mass of the object in kilograms (0 for static objects)
Returns
  A new physics object using the collider's shape
createGLTF ( scene , entity , filename , mass )
Creates a physics object from a GLTF model file.
The collision shape will be generated from the model's geometry.
Signature
fun createGLTF(scene: Scene, entity: Entity?, filename: String, mass: Float): ScenePhysicsObject
Parameters
scene: Scene
  The scene in which to create the physics object
entity: Entity?
  Optional entity to associate with this physics object
filename: String
  Path to the GLTF model file
mass: Float
  Mass of the object in kilograms (0 for static objects)
Returns
  A new physics object based on the GLTF model
createSphere ( scene , entity , radius , mass )
Creates a sphere-shaped physics object.
Signature
fun createSphere(scene: Scene, entity: Entity?, radius: Float, mass: Float): ScenePhysicsObject
Parameters
scene: Scene
  The scene in which to create the physics object
entity: Entity?
  Optional entity to associate with this physics object
radius: Float
  Radius of the sphere in meters
mass: Float
  Mass of the sphere in kilograms (0 for static objects)
Returns
  A new sphere-shaped physics object
setCallbackEntities ( scene , entities )
Sets the entities that will receive physics callbacks.
Signature
fun setCallbackEntities(scene: Long, entities: LongArray)
Parameters
scene: Long
  The scene handle
entities: LongArray
  Array of entity IDs that will receive physics callbacks
Did you find this page helpful?