Guides
Working with Physics

Working with physics

When adding components in the studio like models or avatars. You need to attach a collider in order to for collisions to work on them. This section of the Getting Started tutorial explains how to attach the collider on the studio.

As noted previously, Physics and collision in oncyber is handled via the Rapier (opens in a new tab) library. Rapier is a fast physics engine written using the Rust programming language.

The design of the physics API in scripting was kept minimalistic on purpose. The engine creates the physics world, rigid bodies and colliders from the collider data on the component, then gets out of the way. You can then use the full capabilities of the Rapier physics engine to implement the desired behavior of the game.

The settings of the collider section on the studio mirror the ones used by Rapier. Rigid Bodies can be fixed, dynamic or kinematic. And for collider type you can either chose a predefined shape (Cube, Sphere ...), or use the component mesh as collider.

If possible, opt always for one of the predefined shapes instead of Mesh for the collider type. It'll make the physics simulation way faster.

To access the created the rapier entities for a component, you can use the rigidBody property of the component. From there you can get the Rapier rigid body and the collider

// ...
 
// Get our RigidBody wrapper
const rigidBody = myComponent.rigidBody
 
// Get the rapier colliders
const colliders = myComponent.rigidBody.colliders

For more info on how to use the rapier objects see Rapier docs, particulary for Rigid-bodies (opens in a new tab) and Colliders (opens in a new tab).