Physics
Introduction
Studio has a built-in physics system intended for handling robust and dynamic interactions in your scene.Adding Colliders
nota
- Colliders can be nested in some configurations, but not others. For example, a static collider inside a dynamic collider, or two nested dynamic colliders, could misbehave.
- Unless you have a Geometry component that is also a valid Collider Shape, you’ll need to specify a shape manually. For example there isn’t a supported matching collider for the tetrahedron primitive.
- GLTF model collider generation for complex models might affect performance.
Example
The following example shows how to add a collider to an entity at runtime.
ecs.Collider.set(world, component.eid, {
shape: ecs.ColliderShape.Sphere,
radius,
mass: 1,
eventOnly: false,
lockXAxis: false,
lockYAxis: false,
lockZAxis: false,
friction: 0.5,
restitution: 0.5,
linearDamping: 0,
angularDamping: 0,
rollingFriction: 0.1,
spinningFriction: 0.1,
})
Functions
You can directly apply forces (linear and angular) to any entity with a physics collider. These forces are applied in the next physics simulation update, which takes place at regular intervals. The function accepts a 3D vector to define the force direction and magnitude.