#debug #debugging #bevy #physics #collision #shapes #api

heron_debug

Rendering of Heron’s collision shapes for debugging purposes

14 releases (breaking)

new 0.11.0 Jul 19, 2021
0.9.1 Jun 30, 2021
0.3.0 Mar 21, 2021
Download history 24/week @ 2021-04-04 43/week @ 2021-04-11 56/week @ 2021-04-18 40/week @ 2021-04-25 46/week @ 2021-05-02 19/week @ 2021-05-09 48/week @ 2021-05-16 42/week @ 2021-05-23 50/week @ 2021-05-30 47/week @ 2021-06-06 29/week @ 2021-06-13 16/week @ 2021-06-20 52/week @ 2021-06-27 26/week @ 2021-07-04 35/week @ 2021-07-11 69/week @ 2021-07-18

165 downloads per month
Used in heron

MIT license

130KB
3K SLoC

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 copmonents...
        .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.8.0", features = ["3d"] }

For a 2d game:

bevy = "^0.5.0"
heron = { version = "0.8.0", 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 (but not both). If none of theses two features is enabled, the PhysicsPlugin won't be available.

Enabled by Default

  • 3d Enable simulation on the 3 axes x, y, and z. Incompatible with the feature 2d.

Optional

  • 2d Enable simulation only on the first 2 axes x and y. Incompatible with the feature 3d, therefore require to disable the default features.
  • debug Render collision shapes. Works only in 2d, support for 3d will be added later.

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

~11–25MB
~409K SLoC