rigid_body_forces_and_impulses
In addition to gravity, it is possible to add custom forces (or torques) or apply impulses (or torque impulses) to dynamic rigid-bodies in order to make them move in specific ways. Forces affect the rigid-body's acceleration whereas impulses affect the rigid-body's velocity. They are both based on the familiar equations:
- Forces: the acceleration change is equal to the force divided by the mass:
- Impulses: the velocity change is equal to the impulse divided by the mass:
Forces can be added, and impulses can be applied, to a rigid-body
- Example 2D
- Example 3D
<load path='/2d/rust/examples/rs_rigid_bodies2.rs' marker='Forces' />
<load path='/3d/rust/examples/rs_rigid_bodies3.rs' marker='Forces' />
- Example 2D
- Example 3D
<load path='/2d/bevy/examples/rigid_bodies2.rs' marker='Forces1' />
<load path='/2d/bevy/examples/rigid_bodies2.rs' marker='Forces2' />
<load path='/3d/bevy/examples/rigid_bodies3.rs' marker='Forces1' />
<load path='/3d/bevy/examples/rigid_bodies3.rs' marker='Forces2' />
- Example 2D
- Example 3D
<load path='/2d/javascript/src/snippets/rigid_bodies.ts' marker='Forces' />
<load path='/3d/javascript/src/snippets/rigid_bodies.ts' marker='Forces' />
Keep in mind that a dynamic rigid-body with a zero mass won't be affected by a linear force/impulse, and a rigid-body with a zero angular inertia won't be affected by torques/torque impulses. So if your force doesn't appear to do anything, make sure that:
- The rigid-body is dynamic.
- It is strong enough to make the rigid-body move (try a very large value and see if it does something).
- The rigid-body has a non-zero mass or angular inertia either because they were set explicitly, or because they were computed automatically from colliders with non-zero densities.
wake_up
parameter to true
).