works less bad
This commit is contained in:
parent
3d0d86f24c
commit
aef303ca71
7 changed files with 28 additions and 15 deletions
|
@ -25,16 +25,17 @@ impl Plugin for CyberActionPlugin {
|
||||||
app.init_resource::<MovementSettings>()
|
app.init_resource::<MovementSettings>()
|
||||||
.register_type::<MovementSettings>()
|
.register_type::<MovementSettings>()
|
||||||
.init_resource::<CatControllerSettings>()
|
.init_resource::<CatControllerSettings>()
|
||||||
.init_resource::<ActionDebugInstant>()
|
|
||||||
.init_resource::<CyberLean>()
|
.init_resource::<CyberLean>()
|
||||||
.register_type::<CyberLean>()
|
.register_type::<CyberLean>()
|
||||||
.register_type::<CatControllerSettings>()
|
.register_type::<CatControllerSettings>()
|
||||||
.add_plugins((PhysicsPlugins::default(), FrameTimeDiagnosticsPlugin))
|
.add_plugins((PhysicsPlugins::default(), FrameTimeDiagnosticsPlugin))
|
||||||
.insert_resource(SubstepCount(12))
|
.insert_resource(SubstepCount(24))
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(
|
(
|
||||||
gravity,
|
gravity,
|
||||||
|
#[cfg(feature = "inspector")]
|
||||||
|
debug_bodies,
|
||||||
(cyber_lean, suspension, falling_cat, input_forces).after(clear_forces),
|
(cyber_lean, suspension, falling_cat, input_forces).after(clear_forces),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -7,6 +7,8 @@ use avian3d::{
|
||||||
PrismaticJoint, RigidBodyQuery,
|
PrismaticJoint, RigidBodyQuery,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
#[cfg(feature = "inspector")]
|
||||||
|
use bevy::prelude::Entity;
|
||||||
use bevy::prelude::{Quat, Query, Res, ResMut, Time, Transform, Vec3, With, Without};
|
use bevy::prelude::{Quat, Query, Res, ResMut, Time, Transform, Vec3, With, Without};
|
||||||
|
|
||||||
use super::{CatControllerSettings, CatControllerState, CyberLean, MovementSettings};
|
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 {
|
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;
|
return;
|
||||||
};
|
};
|
||||||
let dt = time.delta_seconds();
|
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);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -66,5 +66,5 @@ pub(super) fn spawn_cyberbike(
|
||||||
})
|
})
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
spawn_wheels(&mut commands, bike, &wheel_conf, &mut meshterials);
|
spawn_wheels(&mut commands, bike, &xform, &wheel_conf, &mut meshterials);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ mod components;
|
||||||
mod wheels;
|
mod wheels;
|
||||||
|
|
||||||
use bevy::{
|
use bevy::{
|
||||||
app::{PostStartup, Startup},
|
app::PostStartup,
|
||||||
prelude::{App, Assets, Mesh, Plugin, ResMut, StandardMaterial},
|
prelude::{App, Assets, Mesh, Plugin, ResMut, StandardMaterial},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,6 +23,6 @@ impl Plugin for CyberBikePlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.insert_resource(WheelConfig::default())
|
app.insert_resource(WheelConfig::default())
|
||||||
.register_type::<WheelConfig>()
|
.register_type::<WheelConfig>()
|
||||||
.add_systems(Startup, spawn_cyberbike);
|
.add_systems(PostStartup, spawn_cyberbike);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ use super::{
|
||||||
pub fn spawn_wheels(
|
pub fn spawn_wheels(
|
||||||
commands: &mut Commands,
|
commands: &mut Commands,
|
||||||
bike: Entity,
|
bike: Entity,
|
||||||
|
xform: &Transform,
|
||||||
conf: &WheelConfig,
|
conf: &WheelConfig,
|
||||||
meshterials: &mut Meshterial,
|
meshterials: &mut Meshterial,
|
||||||
) {
|
) {
|
||||||
|
@ -84,6 +85,9 @@ pub fn spawn_wheels(
|
||||||
AngularVelocity::ZERO,
|
AngularVelocity::ZERO,
|
||||||
ExternalTorque::ZERO,
|
ExternalTorque::ZERO,
|
||||||
))
|
))
|
||||||
|
.insert(SpatialBundle::from_transform(
|
||||||
|
xform.with_translation(xform.translation + offset),
|
||||||
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
let spring = CyberSpring(suspension_axis);
|
let spring = CyberSpring(suspension_axis);
|
||||||
|
@ -95,6 +99,7 @@ pub fn spawn_wheels(
|
||||||
spring,
|
spring,
|
||||||
Collider::sphere(0.1),
|
Collider::sphere(0.1),
|
||||||
ColliderDensity(0.1),
|
ColliderDensity(0.1),
|
||||||
|
CollisionLayers::from_bits(0, 0),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
@ -103,9 +108,12 @@ pub fn spawn_wheels(
|
||||||
spring,
|
spring,
|
||||||
Collider::sphere(0.1),
|
Collider::sphere(0.1),
|
||||||
ColliderDensity(0.1),
|
ColliderDensity(0.1),
|
||||||
|
CollisionLayers::from_bits(0, 0),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
.insert(SpatialBundle::default())
|
.insert(SpatialBundle::from_transform(
|
||||||
|
xform.with_translation(xform.translation + offset),
|
||||||
|
))
|
||||||
.id();
|
.id();
|
||||||
let axel_joint = RevoluteJoint::new(axel, wheel).with_aligned_axis(Vec3::NEG_X);
|
let axel_joint = RevoluteJoint::new(axel, wheel).with_aligned_axis(Vec3::NEG_X);
|
||||||
commands.spawn(axel_joint);
|
commands.spawn(axel_joint);
|
||||||
|
|
|
@ -29,13 +29,12 @@ fn main() {
|
||||||
CyberSpaceLightsPlugin,
|
CyberSpaceLightsPlugin,
|
||||||
CyberUIPlugin,
|
CyberUIPlugin,
|
||||||
CyberBikePlugin,
|
CyberBikePlugin,
|
||||||
|
#[cfg(feature = "inspector")]
|
||||||
|
CyberGlamorPlugin,
|
||||||
))
|
))
|
||||||
.add_systems(Startup, disable_mouse_trap)
|
.add_systems(Startup, disable_mouse_trap)
|
||||||
.add_systems(Update, close_on_esc);
|
.add_systems(Update, close_on_esc);
|
||||||
|
|
||||||
#[cfg(feature = "inspector")]
|
|
||||||
app.add_plugin(CyberGlamorPlugin);
|
|
||||||
|
|
||||||
app.run();
|
app.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,6 @@ use bevy::{
|
||||||
TextBundle, TextSection, TextStyle, Transform, With,
|
TextBundle, TextSection, TextStyle, Transform, With,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
#[cfg(feature = "inspector")]
|
|
||||||
use bevy_inspector_egui::quick::WorldInspectorPlugin;
|
|
||||||
|
|
||||||
use crate::bike::CyberBikeBody;
|
use crate::bike::CyberBikeBody;
|
||||||
|
|
||||||
|
@ -53,9 +51,6 @@ pub struct CyberUIPlugin;
|
||||||
|
|
||||||
impl Plugin for CyberUIPlugin {
|
impl Plugin for CyberUIPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
#[cfg(feature = "inspector")]
|
|
||||||
app.add_plugin(WorldInspectorPlugin);
|
|
||||||
|
|
||||||
app.add_systems(Startup, setup_ui)
|
app.add_systems(Startup, setup_ui)
|
||||||
.add_systems(Update, update_ui);
|
.add_systems(Update, update_ui);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue