#physics-engine #bevy #box #2d #sensors #collision #overlap

bevy_2d_box_physics

A 2D box-collision physics engine for use with the bevy engine

2 releases

0.1.1 Jan 3, 2023
0.1.0 Jan 2, 2023

#1337 in Game dev

Download history 1/week @ 2024-02-14 6/week @ 2024-02-21 2/week @ 2024-02-28 21/week @ 2024-03-27 31/week @ 2024-04-03

52 downloads per month

MIT license

36KB
798 lines

bevy_2d_box_physics

A 2D box-collision physics engine for use with the bevy engine

Usage

For the physics to work the PhysicsPlugin must be added. For adding forces/velocity to objects you can add the PhysicsBundle and for collisions (only collisionboxes are and will be supported) there is the CollisionBundle. Sensors, which lets us get information when two objects overlap can also be added with the SensorBundle. A very simple example can be seen below:

use bevy::prelude::*;
use bevy_2d_box_physics::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(PhysicsPlugin)
        .add_startup_system(setup)
        .run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn_bundle(PhysicsBundle {
        rigidbody: RigidBody::Dynamic,
        ..default()
    })
    .insert(CollisionBundle {
        collision_box: CollisionBox(16.0, 16.0),
        collision_layers: CollisionLayers {
            layer_id: 0,
            collides_with_ids: vec![0, 1],
        },
        ..default()
    })
}

(Note that this doesn't do much as there are no textures, but hopefully you get the idea)

Dependencies

~35–51MB
~694K SLoC