added wheelconfig struct and hooked in egui inspector

This commit is contained in:
Joe Ardent 2023-01-23 22:21:16 -08:00
parent bf35c963b2
commit 9b12967abd

View file

@ -1,3 +1,5 @@
use std::fmt::Debug;
use bevy::prelude::*; use bevy::prelude::*;
use bevy_rapier3d::{ use bevy_rapier3d::{
geometry::Group, geometry::Group,
@ -27,6 +29,32 @@ pub struct CyberBikeControl {
pub prev_error: f32, pub prev_error: f32,
} }
#[derive(Resource, Reflect)]
#[reflect(Resource)]
pub struct WheelConfig {
pub front_forward: f32,
pub front_stance: f32,
pub rear_back: f32,
pub y: f32,
pub limits: [f32; 2],
pub stiffness: f32,
pub damping: f32,
}
impl Default for WheelConfig {
fn default() -> Self {
Self {
front_forward: 0.9,
front_stance: 1.2,
rear_back: 1.1,
y: -1.0,
limits: [0.1, 1.0],
stiffness: 10.0,
damping: 0.7,
}
}
}
const BIKE_BODY_COLLISION_GROUP: (Group, Group) = (Group::GROUP_1, Group::GROUP_1); const BIKE_BODY_COLLISION_GROUP: (Group, Group) = (Group::GROUP_1, Group::GROUP_1);
const BIKE_WHEEL_COLLISION_GROUP: (Group, Group) = (Group::GROUP_10, Group::GROUP_10); const BIKE_WHEEL_COLLISION_GROUP: (Group, Group) = (Group::GROUP_10, Group::GROUP_10);
@ -117,7 +145,7 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
let trans = xform.translation + offset; let trans = xform.translation + offset;
let wheel_pos_in_world = Transform::from_rotation(xform.rotation).with_translation(trans); let wheel_pos_in_world = Transform::from_rotation(xform.rotation).with_translation(trans);
let wheel_damping = Damping { let wheel_damping = Damping {
angular_damping: 0.8, linear_damping: 0.8,
..Default::default() ..Default::default()
}; };
let wheel_collider = Collider::ball(wheel_rad); let wheel_collider = Collider::ball(wheel_rad);
@ -149,6 +177,8 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
pub struct CyberBikePlugin; pub struct CyberBikePlugin;
impl Plugin for CyberBikePlugin { impl Plugin for CyberBikePlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike); app.insert_resource(WheelConfig::default())
.register_type::<WheelConfig>()
.add_startup_system_to_stage(StartupStage::PostStartup, spawn_cyberbike);
} }
} }