Crate heron[−][src]
An ergonomic physics API for 2d and 3d bevy games. (powered by rapier)
Get started
Add the dependency
Add the library to Cargo.toml
heron = "0.1.0-alpha.1"
If you are creating a 2d game, change the default features:
heron = \{ version = "0.1.0-alpha.1", default-features = false, features = ["2d"] }
Note: when debugging you may consider enabling the debug
feature, to render the collision shapes (works only for 2d, at the moment).
Install the plugin
To enable physics and collision detection, the PhysicsPlugin
should be installed
use bevy::prelude::*; use heron::prelude::*; fn main() { App::build() .add_plugins(DefaultPlugins) .add_plugin(PhysicsPlugin::default()) // ... Add your resources and systems .run(); }
Create rigid bodies
To create a rigid body, add the component Body
to the entity, choosing a collision shape.
It will turn the entity into a dynamic rigid body affected by physics.
The position, and rotation is defined by the bevy GlobalTransform
component.
fn spawn(commands: &mut Commands) { commands .spawn(SpriteBundle::default()) // Spawn any bundle of your choice. Only make sure there is a `GlobalTransform` .with(Body::Sphere { radius: 10.0 }) // Make it a physics body, by attaching a collision shape .with(Velocity::from(Vec2::unit_x() * 2.0)); // Optionally add a velocity component }
It is also possible to:
- Define the world's
Gravity
- Listen to
CollisionEvent
- Define body's
Restitution
Modules
prelude | Re-exports of the most commons/useful types |
rapier_plugin | Physics behavior powered by rapier |
utils | Utility traits and extensions |
Structs
AxisAngle | An axis-angle representation |
Gravity | Resource that defines world's gravity. |
PhysicsPlugin | Plugin to install in order to enable collision detection and physics behavior. |
Restitution | Component that define the Coefficient of Restitution |
Velocity | Component that defines the linear and angular velocity. |
Enums
Body | Components that define a body subject to physics and collision |
CollisionEvent | An event fired when the collision state between two entities changed |