rigid_body_creation_and_insertion
A rigid-body is created by adding the RigidBody
component to an entity. Other components
like Transform
, Velocity
, Ccd
, etc. can be added for further customization of the
rigid-body.
info
The following example shows several initialization of components to customize rigid-body 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
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;
commands
.spawn(RigidBody::Dynamic)
.insert(TransformBundle::from(Transform::from_xyz(0.0, 5.0, 0.0)))
.insert(Velocity {
linvel: Vec2::new(1.0, 2.0),
angvel: 0.2,
})
.insert(GravityScale(0.5))
.insert(Sleeping::disabled())
.insert(Ccd::enabled());
use bevy::prelude::*;
use bevy_rapier3d::prelude::*;
commands
.spawn(RigidBody::Dynamic)
.insert(TransformBundle::from(Transform::from_xyz(0.0, 0.0, 0.0)))
.insert(Velocity {
linvel: Vec3::new(0.0, 2.0, 0.0),
angvel: Vec3::new(0.2, 0.0, 0.0),
})
.insert(GravityScale(0.5))
.insert(Sleeping::disabled())
.insert(Ccd::enabled());
info
Typically, the inertia and center of mass are automatically set to the inertia and center of mass resulting from the shapes of the colliders attached to the rigid-body. But they can also be set manually.