Skip to main content

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.

info

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.

<load path='/2d/rust/examples/rs_colliders2.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.

info

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.

<load path='/2d/bevy/examples/colliders2.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:

  1. Attach the Collider to the same entity as the RigidBody.
  2. Attach the Collider to an entity that is a child of the entity containing the RigidBody.
<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.

info

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.

<load path='/2d/javascript/src/snippets/colliders.ts' marker='Creation' />