bevy_2d_box_physics

Crates.iobevy_2d_box_physics
lib.rsbevy_2d_box_physics
version0.1.1
sourcesrc
created_at2023-01-02 21:25:56.308203
updated_at2023-01-03 19:49:05.330063
descriptionA 2D box-collision physics engine for use with the bevy engine
homepage
repositoryhttps://codeberg.org/magnouvean/bevy_2d_box_physics
max_upload_size
id749672
size36,652
(magnouvean)

documentation

README

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)

Commit count: 0

cargo fmt