collider_creation_and_insertion
A collider is created by a ColliderBuilder
structure that is based on the builder pattern. Then it needs
to be inserted into the ColliderSet
that will be processed by the physics-pipeline, collision-pipeline, or
query-pipeline.
The following example shows several setters that can be called to customize the collider being built. The input values are just random so using this example as-is will not lead to a useful result.
- Example 2D
- Example 3D
<load path='/2d/rust/examples/rs_colliders2.rs' marker='Creation' />
<load path='/3d/rust/examples/rs_colliders3.rs' marker='Creation' />
A collider is created by adding the Collider
component. Other components like Transform
,
Sensor
, Friction
, etc. can be added to customize the collider.
The following example shows several initializations of components to customize collider being built. The input values are just random so using this example as-is will not lead to a useful result.
- Example 2D
- Example 3D
<load path='/2d/bevy/examples/colliders2.rs' marker='Creation1' />
<load path='/3d/bevy/examples/colliders3.rs' marker='Creation1' />
A collider can optionally be attached to a rigid-body. Attaching a collider to a rigid-body will result in the rigid-body being affected by collisions. The collider's position will be automatically updated from the position of the rigid-body it is attached to. There are two ways of attaching a collider to a rigid-body. The second way allows you to attach multiple colliders to the same rigid-body:
- Attach the
Collider
to the same entity as theRigidBody
. - Attach the
Collider
to an entity that is a child of the entity containing theRigidBody
.
<load path='/2d/bevy/examples/colliders2.rs' marker='Creation2' />
A collider is created by a World.createCollider
method. The initial state of
the collider to create is described by an instance of the ColliderDesc
class.
Each collider create by the physics world is given an integer identifier. This identifier
is guaranteed to the different from any identifier of colliders still existing in the physics
world. However, the identifier may be equal to the identifier of an older collider that has
already been removed from the physics world with World.removeCollider
.
The following example shows several setters that can be called to customize the collider being built. The input values are just random so using this example as-is will not lead to a useful result.
- Example 2D
- Example 3D
<load path='/2d/javascript/src/snippets/colliders.ts' marker='Creation' />
<load path='/3d/javascript/src/snippets/colliders.ts' marker='Creation' />