Beginning work with collision detection
Some checks failed
Basic checks / Basic build-and-test supertask (push) Failing after 31s

I'm going to grab the Rapier physics library so that I don't have to do
my own collision detection mechanism. The last time I did this, I
simplified everything into circles. This time I'd like to have convex
hulls, particularly for the player ship.

Also the last time, I ended up rolling my own quadtree impl. I'm not
particularly interested in doing that again, and I'd like to learn more
of the broader Bevy ecosystem.
This commit is contained in:
2025-08-06 13:05:12 -05:00
parent 96e9376330
commit f553574e3e
3 changed files with 14 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
use bevy_rapier2d::prelude::Collider;
use rand::{Rng, SeedableRng};
use std::time::Duration;
@@ -107,8 +108,16 @@ pub fn spawn_asteroid(
AsteroidSize::Medium => game_assets.asteroid_medium(),
AsteroidSize::Large => game_assets.asteroid_large(),
};
let collider_radius = match spawn.size {
AsteroidSize::Small => 10.0,
AsteroidSize::Medium => 20.0,
AsteroidSize::Large => 40.0,
};
commands.spawn((
Asteroid(AsteroidSize::Small),
Collider::ball(collider_radius),
Position(spawn.pos),
Velocity(spawn.vel),
Rotation(0.0),

View File

@@ -10,6 +10,7 @@ use bevy::prelude::*;
use bevy_inspector_egui::InspectorOptions;
use bevy_inspector_egui::prelude::ReflectInspectorOptions;
use bevy_rapier2d::{plugin::{NoUserData, RapierPhysicsPlugin}, prelude::Collider, render::RapierDebugRenderPlugin};
use config::{ASTEROID_SMALL_COLOR, SHIP_THRUSTER_COLOR_ACTIVE, SHIP_THRUSTER_COLOR_INACTIVE};
pub struct AsteroidPlugin;
@@ -19,6 +20,8 @@ impl Plugin for AsteroidPlugin {
app.add_plugins((
title_screen::GameMenuPlugin,
preparation_widget::preparation_widget_plugin,
RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(10.0),
RapierDebugRenderPlugin::default(),
))
.insert_resource(ClearColor(BACKGROUND_COLOR))
.insert_resource(WorldSize {
@@ -176,6 +179,7 @@ fn spawn_camera(mut commands: Commands) {
fn spawn_player(mut commands: Commands, game_assets: Res<GameAssets>) {
commands
.spawn((
Collider::ball(0.7),
Ship,
Wrapping,
Position(Vec2::default()),