25 releases (13 stable)

Uses new Rust 2021

new 3.1.0 May 20, 2022
3.0.0 Apr 17, 2022
2.4.1 Apr 15, 2022
2.3.0 Mar 23, 2022
0.11.0 Jul 19, 2021

#534 in Game dev

Download history 132/week @ 2022-01-30 101/week @ 2022-02-06 133/week @ 2022-02-13 293/week @ 2022-02-20 469/week @ 2022-02-27 228/week @ 2022-03-06 224/week @ 2022-03-13 259/week @ 2022-03-20 169/week @ 2022-03-27 290/week @ 2022-04-03 260/week @ 2022-04-10 345/week @ 2022-04-17 271/week @ 2022-04-24 328/week @ 2022-05-01 274/week @ 2022-05-08 772/week @ 2022-05-15

1,697 downloads per month
Used in 4 crates (via heron)

MIT license

3KB

Heron

License Crates.io Docs dependency status Bevy tracking Build Zenhub

An ergonomic physics API for 2d and 3d bevy games. (powered by rapier)

How it looks like

use bevy::prelude::*;
use heron::prelude::*;

fn main() {
  App::build()
    .add_plugins(DefaultPlugins)
    .add_plugin(PhysicsPlugin::default()) // Add the plugin
    .insert_resource(Gravity::from(Vec3::new(0.0, -9.81, 0.0))) // Optionally define gravity
    .add_startup_system(spawn.system())
    .run();
}

fn spawn(mut commands: Commands) {
    commands

        // Spawn any bundle of your choice. Only make sure there is a `GlobalTransform`
        .spawn_bundle(SpriteBundle::default())

        // Make it a rigid body
        .insert(RigidBody::Dynamic)
        
        // Attach a collision shape
        .insert(CollisionShape::Sphere { radius: 10.0 })
        
        // Optionally add other useful components...
        .insert(Velocity::from_linear(Vec3::X * 2.0))
        .insert(Acceleration::from_linear(Vec3::X * 1.0))
        .insert(PhysicMaterial { friction: 1.0, density: 10.0, ..Default::default() })
        .insert(RotationConstraints::lock())
        .insert(CollisionLayers::none().with_group(Layer::Player).with_mask(Layer::World));
}

// Define your physics layers
#[derive(PhysicsLayer)]
enum Layer {
    World,
    Player,
    Enemies,
}

Installation

For a 3d game:

bevy = "^0.5.0"
heron = { version = "0.12.1", features = ["3d"] }

For a 2d game:

bevy = "^0.5.0"
heron = { version = "0.12.1", features = ["2d"] }

Bevy Version Supported

bevy heron
0.5 >= 0.4
0.4 < 0.4

Design principles

  • Use bevy types, resources and components when possible (Vec3, Quat, Transform, Events, etc.)
  • Provide a single API that works for both 2d and 3d. (Like bevy does)
  • Data oriented. Using this library should look like it is part of bevy.
  • Avoid asking the user to lookup in resources via handles. Data should be accessible and modifiable directly in components.
  • Hide the actual physics engine. This is an implementation detail the user shouldn't have to care about.
    • But, allow advanced users to access the underlying rapier resources, so a user is never blocked by a missing element in the API of heron.

Feature flags

One must choose to use either 2d or 3d. If none of theses two features is enabled, the PhysicsPlugin won't be available.

  • 3d Enable simulation on the 3 axes x, y, and z.
  • 2d Enable simulation only on the first 2 axes x and y.
  • debug-2d Render 2d collision shapes.
  • debug-3d Render 3d collision with wireframes.

How does this project compare to bevy_rapier?

bevy_rapier plugin is an excellent option and should definitely be considered.

Here are some key differences between the two projects:

  • heron tries to provide a smaller, simpler API that is easier to use. bevy_rapier is more complete and powerful, but a bit more complex.
  • heron mostly hides the underlying physics engine, so you don't have to use rapier directly nor nalgebra. bevy_rapier asks the user to deal directly with rapier and nalgebra.
  • heron is focused on games only. bevy_rapier targets all kind of physics simulation applications (incl. games).
  • bevy_rapier is actively maintained by dimforge, the developer of rapier. heron is also active, but cannot evolve as fast as bevy_rapier can.

heron is probably more suited for simple games and game-jams, where the ease of learn/use is especially valuable and where the lack of advanced feature isn't problematic.

bevy_rapier is probably more suited for bigger/complex games and other types of physics simulations, where it may be better to learn/use a more exhaustive/complex API.

Contribute / Contact

You can open issues/discussions here or you can discuss with me (Jomag#2675) in the bevy discord

See how to contribute

Dependencies

~250–660KB
~16K SLoC