#assets #bevy #gamedev #game

butsuri

Currently only an asset that provides 2d collision detertor and kinematics, build from scratch in bevy

1 unstable release

0.1.0 May 9, 2022

#1990 in Game dev

MIT license

26KB
276 lines

Busturi

latest version

A physics engine An asset that provides 2d collision detertor and kinematics, build from scratch in bevy

How to use

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>,
) {
	// ...
}

Examples

  • Collision: a group of sprites that change color when they collide
  • Player Input: similar to the previous example but there is a player that is controlled by applying velocity with the w/a/s/d keys
  • Gravity: shows how to activate and use gravity

How useful is this project compared to other similar ones?

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.

Dependencies

~43MB
~697K SLoC