rigid_body_position
The position of a rigid-body represents its location (translation) in 2D or 3D world-space, as well as its orientation (rotation).
Transform
component
The position of a rigid-body can be set when creating it. It can also be set after its creation as illustrated below.
Directly changing the position of a rigid-body is equivalent to teleporting it: this is a not a physically realistic action! Teleporting a dynamic or kinematic bodies may result in odd behaviors especially if it teleports into a space occupied by other objects. For dynamic bodies, forces, impulses, or velocity modification should be preferred. For kinematic bodies, see the discussion after the examples below.
- Example 2D
- Example 3D
<load path='/2d/rust/examples/rs_rigid_bodies2.rs' marker='Position1' />
<load path='/2d/rust/examples/rs_rigid_bodies2.rs' marker='Position2' />
<load path='/3d/rust/examples/rs_rigid_bodies3.rs' marker='Position1' />
<load path='/3d/rust/examples/rs_rigid_bodies3.rs' marker='Position2' />
- Example 2D
- Example 3D
<load path='/2d/bevy/examples/rigid_bodies2.rs' marker='Position1' />
<load path='/2d/bevy/examples/rigid_bodies2.rs' marker='Position2' />
<load path='/3d/bevy/examples/rigid_bodies3.rs' marker='Position1' />
<load path='/3d/bevy/examples/rigid_bodies3.rs' marker='Position2' />
- Example 2D
- Example 3D
<load path='/2d/javascript/src/snippets/rigid_bodies.ts' marker='Position1' />
<load path='/2d/javascript/src/snippets/rigid_bodies.ts' marker='Position2' />
<load path='/3d/javascript/src/snippets/rigid_bodies.ts' marker='Position1' />
<load path='/3d/javascript/src/snippets/rigid_bodies.ts' marker='Position2' />
In order to move a dynamic rigid-body it is strongly discouraged to set its position directly as it may results in weird behaviors: it's as if the rigid-body teleports itself, which is a non-physical behavior. For dynamic bodies, it is recommended to either set its velocity or to apply forces or impulses.
For velocity-based kinematic bodies, it is recommended to set its velocity instead of setting its position directly. For position-based kinematic bodies, it is recommended to use the special methods:
RigidBody::set_next_kinematic_rotation
RigidBody::set_next_kinematic_translation
These methods will let the physics pipeline compute the fictitious velocity of the position-based kinematic body for more realistic interactions with other rigid-bodies. These methods won't immediately modify the position of the kinematic body itself. The position of the kinematic body will be automatically set to these values during the next physics pipeline update.
For velocity-based kinematic bodies, it is recommended to set its velocity instead of setting its position directly.
For position-based kinematic bodies, it is recommended to modify its Transform
(changing its velocity won’t have
any effect). This will let the physics engine compute the fictitious velocity of the kinematic body for more
realistic intersections with other rigid-bodies.
For velocity-based kinematic bodies, it is recommended to set its velocity instead of setting its position directly. For position-based kinematic bodies, it is recommended to use the special methods:
RigidBody.setNextKinematicRotation
RigidBody.setNextKinematicTranslation
These methods will let the physics pipeline compute the fictitious velocity of the position-based kinematic body for more realistic interactions with other rigid-bodies. These methods won't immediately modify the position of the kinematic body itself. The position of the kinematic body will be automatically set to these values during the next physics pipeline update.