diff --git a/src/action/mod.rs b/src/action/mod.rs index fe08eeb..83fe8ba 100644 --- a/src/action/mod.rs +++ b/src/action/mod.rs @@ -25,16 +25,17 @@ impl Plugin for CyberActionPlugin { app.init_resource::() .register_type::() .init_resource::() - .init_resource::() .init_resource::() .register_type::() .register_type::() .add_plugins((PhysicsPlugins::default(), FrameTimeDiagnosticsPlugin)) - .insert_resource(SubstepCount(12)) + .insert_resource(SubstepCount(24)) .add_systems( Update, ( gravity, + #[cfg(feature = "inspector")] + debug_bodies, (cyber_lean, suspension, falling_cat, input_forces).after(clear_forces), ), ); diff --git a/src/action/systems.rs b/src/action/systems.rs index f0a39c1..b410b22 100644 --- a/src/action/systems.rs +++ b/src/action/systems.rs @@ -7,6 +7,8 @@ use avian3d::{ PrismaticJoint, RigidBodyQuery, }, }; +#[cfg(feature = "inspector")] +use bevy::prelude::Entity; use bevy::prelude::{Quat, Query, Res, ResMut, Time, Transform, Vec3, With, Without}; use super::{CatControllerSettings, CatControllerState, CyberLean, MovementSettings}; @@ -148,7 +150,7 @@ pub(super) fn input_forces( >, ) { let Ok((mut bike, xform, mass, mut forces)) = body_query.get_single_mut() else { - bevy::log::warn!("no bike body found"); + bevy::log::debug!("no bike body found"); return; }; let dt = time.delta_seconds(); @@ -185,3 +187,11 @@ pub(super) fn input_forces( fork.align_orientation(&mut axle, &mut bike, diff, &mut compliance, 1.0, dt); } + +#[cfg(feature = "inspector")] +pub(super) fn debug_bodies(bodies: Query<(Entity, RigidBodyQuery)>) { + for (entity, rbq) in bodies.iter().filter(|(_, r)| r.rb.is_dynamic()) { + let line = format!("{entity:?} at {:?}", rbq.current_position()); + bevy::log::info!(line); + } +} diff --git a/src/bike/body.rs b/src/bike/body.rs index ed3679b..c7a7487 100644 --- a/src/bike/body.rs +++ b/src/bike/body.rs @@ -66,5 +66,5 @@ pub(super) fn spawn_cyberbike( }) .id(); - spawn_wheels(&mut commands, bike, &wheel_conf, &mut meshterials); + spawn_wheels(&mut commands, bike, &xform, &wheel_conf, &mut meshterials); } diff --git a/src/bike/mod.rs b/src/bike/mod.rs index 2c2fe03..212ec24 100644 --- a/src/bike/mod.rs +++ b/src/bike/mod.rs @@ -3,7 +3,7 @@ mod components; mod wheels; use bevy::{ - app::{PostStartup, Startup}, + app::PostStartup, prelude::{App, Assets, Mesh, Plugin, ResMut, StandardMaterial}, }; @@ -23,6 +23,6 @@ impl Plugin for CyberBikePlugin { fn build(&self, app: &mut App) { app.insert_resource(WheelConfig::default()) .register_type::() - .add_systems(Startup, spawn_cyberbike); + .add_systems(PostStartup, spawn_cyberbike); } } diff --git a/src/bike/wheels.rs b/src/bike/wheels.rs index f846522..15636cb 100644 --- a/src/bike/wheels.rs +++ b/src/bike/wheels.rs @@ -9,6 +9,7 @@ use super::{ pub fn spawn_wheels( commands: &mut Commands, bike: Entity, + xform: &Transform, conf: &WheelConfig, meshterials: &mut Meshterial, ) { @@ -84,6 +85,9 @@ pub fn spawn_wheels( AngularVelocity::ZERO, ExternalTorque::ZERO, )) + .insert(SpatialBundle::from_transform( + xform.with_translation(xform.translation + offset), + )) .id(); let spring = CyberSpring(suspension_axis); @@ -95,6 +99,7 @@ pub fn spawn_wheels( spring, Collider::sphere(0.1), ColliderDensity(0.1), + CollisionLayers::from_bits(0, 0), )) } else { commands.spawn(( @@ -103,9 +108,12 @@ pub fn spawn_wheels( spring, Collider::sphere(0.1), ColliderDensity(0.1), + CollisionLayers::from_bits(0, 0), )) } - .insert(SpatialBundle::default()) + .insert(SpatialBundle::from_transform( + xform.with_translation(xform.translation + offset), + )) .id(); let axel_joint = RevoluteJoint::new(axel, wheel).with_aligned_axis(Vec3::NEG_X); commands.spawn(axel_joint); diff --git a/src/main.rs b/src/main.rs index 090dbd5..3c8b984 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,13 +29,12 @@ fn main() { CyberSpaceLightsPlugin, CyberUIPlugin, CyberBikePlugin, + #[cfg(feature = "inspector")] + CyberGlamorPlugin, )) .add_systems(Startup, disable_mouse_trap) .add_systems(Update, close_on_esc); - #[cfg(feature = "inspector")] - app.add_plugin(CyberGlamorPlugin); - app.run(); } diff --git a/src/ui.rs b/src/ui.rs index de53559..a7be79d 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -6,8 +6,6 @@ use bevy::{ TextBundle, TextSection, TextStyle, Transform, With, }, }; -#[cfg(feature = "inspector")] -use bevy_inspector_egui::quick::WorldInspectorPlugin; use crate::bike::CyberBikeBody; @@ -53,9 +51,6 @@ pub struct CyberUIPlugin; impl Plugin for CyberUIPlugin { fn build(&self, app: &mut App) { - #[cfg(feature = "inspector")] - app.add_plugin(WorldInspectorPlugin); - app.add_systems(Startup, setup_ui) .add_systems(Update, update_ui); }