2 releases
0.1.1 | Jan 3, 2023 |
---|---|
0.1.0 | Jan 2, 2023 |
#1750 in Game dev
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
~32–46MB
~784K SLoC