Button, Trigger, TriggerArea, Spinner, UpAndDown)SystemBase to implement frame-by-frame logic for input handling, spatial overlap detection, and animationregisterEventListener and sendEvent with custom event payloadsglXFManagerPhysicsSample directory in Android Studio, connect your Meta Quest device, and run the project. The sample loads a marble run scene with three colored balls positioned at the top of a ramp track. When you press the button, the balls launch and interact with ramps, trigger zones, and moving obstacles. For build configuration and dependency details, refer to the sample’s README.| File / Scene | What it demonstrates | Topics covered |
|---|---|---|
PhysicsSampleActivity.kt (BallRunActivity class) | Main activity orchestrating physics features, component registration, glXF scene loading, event listeners, and game state transitions | AppSystemActivity, PhysicsFeature, glXFManager.inflateGLXF(), Entity.registerEventListener(), Physics component manipulation |
ButtonSystem.kt | Frame-by-frame input handling and smooth animation of a 3D button using lerp | SystemBase.execute(), Query.where, SceneObject.addInputListener(), DataModel.sendEvent() |
TriggerSystem.kt | Spatial overlap detection between balls and trigger zones, dispatching custom events with direction and force values | SystemBase, AABB overlap testing, TriggerEventArgs, Quaternion.times() for direction calculation |
SpinnerSystem.kt | Continuous Y-axis rotation applied to kinematic entities | SystemBase, Quaternion composition with delta time |
UpAndDownSystem.kt | Sinusoidal vertical animation with staggered phase offsets for multiple platforms | SystemBase, changed(Mesh.id) query, sin() animation |
Button.xml, Trigger.xml, TriggerArea.xml, Spinner.xml, UpAndDown.xml | Custom component schema definitions with typed attributes | XML component registration, StringAttribute, FloatAttribute, Vector3Attribute |
TriggerEventArgs.kt | Custom event payload carrying direction and force values | Extending EventArgs with custom data |
Main.metaspatial / Main.scene | Spatial Editor project and scene composition defining entity positions, physics properties, and component assignments | Scene composition, component attribute configuration in the editor |
InfoPanel.kt, WelcomePanel.kt | Compose-based UI panels using the Spatial UISet theme | ComposeViewPanelRegistration, SpatialTheme, Jetpack Compose in 3D space |
Physics component:physics.linearVelocity = Vector3(0f) physics.state = PhysicsState.DYNAMIC physics.applyForce = direction * Vector3(speed)
UpAndDown component, for example, declares amount, speed, offset, and startPosition, which UpAndDownSystem reads each frame to animate vertical oscillation.<Component name="UpAndDown"> <FloatAttribute name="amount" defaultValue="0.1f" /> <FloatAttribute name="speed" defaultValue="0.5f" /> </Component>
onCreate() with componentManager.registerComponent<UpAndDown>(UpAndDown.Companion). For the full set of schemas, see app/src/main/components/. The Custom components documentation uses this sample’s UpAndDown component as its primary teaching example.SystemBase and overrides execute(), which runs every frame. The sample uses Query.where to find entities with specific components, then reads and writes component data. SpinnerSystem applies a Y-axis rotation increment each frame using quaternion multiplication with delta time:transform.transform.q =
transform.transform.q * Quaternion(0f, spinner.speed * timeDeltaInSeconds, 0f)
entity.setComponent(transform)
TriggerSystem sends custom events when a ball enters a trigger zone, and the activity registers listeners on each ball to respond. TriggerEventArgs extends EventArgs to carry direction and force values as a custom payload.ball.entity.registerEventListener<TriggerEventArgs>("speed_up") { entity, args ->
shootBall(entity, args.direction, args.value)
}
TriggerSystem dispatches events via dataModel.sendEvent() when overlap is detected. For the complete event flow, see TriggerSystem.kt and PhysicsSampleActivity.kt. Learn more in the Events documentation.SystemBase to implement behaviors