Crates.io | bevy_2d_box_physics |
lib.rs | bevy_2d_box_physics |
version | 0.1.1 |
source | src |
created_at | 2023-01-02 21:25:56.308203 |
updated_at | 2023-01-03 19:49:05.330063 |
description | A 2D box-collision physics engine for use with the bevy engine |
homepage | |
repository | https://codeberg.org/magnouvean/bevy_2d_box_physics |
max_upload_size | |
id | 749672 |
size | 36,652 |
A 2D box-collision physics engine for use with the bevy engine
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)