Crates.io | butsuri |
lib.rs | butsuri |
version | 0.1.0 |
source | src |
created_at | 2022-05-09 01:31:46.15406 |
updated_at | 2022-05-09 01:31:46.15406 |
description | Currently only an asset that provides 2d collision detertor and kinematics, build from scratch in bevy |
homepage | |
repository | https://github.com/NemuiSen/bustsuri |
max_upload_size | |
id | 582844 |
size | 102,950 |
A physics engine An asset that provides 2d collision detertor and kinematics, build from scratch in bevy
Add PhysicsPlugin to the program and optionally also DebugPlugin to see the collisions of the entities.
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(PhysicsPlugin::default())
// This plugin allows us to see the collisions
//.add_plugin(DebugPlugin)
Then after creating an entity with at least the Transform component insert the CollisionShape component to detect the collisions and who it collided with, and if you want insert the KinematicBundle that the entity has physical properties such as speed, acceleration, or strength
commands.spawn_bundle(SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::splat(100.)),
color: Color::CYAN,
..Default::default()
},
..Default::default()
})
// The size you pass to ColliderShape::AABB(_, _) should be half what you want
.insert(ColliderShape::AABB(50., 50.));
In the end it should be something similar to the following example
use bevy::prelude::*;
use butsuri::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(PhysicsPlugin::default())
.add_system(setup)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn_bundle(SpriteBundle {
sprite: Sprite {
custom_size: Some(Vec2::splat(100.)),
color: Color::CYAN,
..Default::default()
},
..Default::default()
})
.insert(ColliderShape::AABB(50., 50.));
}
// handle collisions as you want
fn collision(
mut collision_event: EventReader<CollisionEvent>,
mut query: Query<&mut Sprite>,
) {
// ...
}
Little, because there are better options that offer more features for example heron or bevy_rapier. I did this project to learn how physics engines work from the inside and i'm a bit lost with things like momentum, but i'll keep updating this project to improve my knowledge, which I'm open to criticism or recommendations.
if you want to contact me you can do it by discord (NemuiSen#4114
) on the Bevy server
PS: I'm sorry if something doesn't make sense, I'm using my vague knowledge of English and google translate to write this.