works less bad

This commit is contained in:
Joe Ardent 2024-07-15 22:47:36 -07:00
parent 3d0d86f24c
commit aef303ca71
7 changed files with 28 additions and 15 deletions

View File

@ -25,16 +25,17 @@ impl Plugin for CyberActionPlugin {
app.init_resource::<MovementSettings>()
.register_type::<MovementSettings>()
.init_resource::<CatControllerSettings>()
.init_resource::<ActionDebugInstant>()
.init_resource::<CyberLean>()
.register_type::<CyberLean>()
.register_type::<CatControllerSettings>()
.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),
),
);

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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::<WheelConfig>()
.add_systems(Startup, spawn_cyberbike);
.add_systems(PostStartup, spawn_cyberbike);
}
}

View File

@ -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);

View File

@ -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();
}

View File

@ -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);
}