added wheelconfig struct and hooked in egui inspector
This commit is contained in:
parent
bf35c963b2
commit
9b12967abd
1 changed files with 32 additions and 2 deletions
34
src/bike.rs
34
src/bike.rs
|
@ -1,3 +1,5 @@
|
|||
use std::fmt::Debug;
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_rapier3d::{
|
||||
geometry::Group,
|
||||
|
@ -27,6 +29,32 @@ pub struct CyberBikeControl {
|
|||
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_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 wheel_pos_in_world = Transform::from_rotation(xform.rotation).with_translation(trans);
|
||||
let wheel_damping = Damping {
|
||||
angular_damping: 0.8,
|
||||
linear_damping: 0.8,
|
||||
..Default::default()
|
||||
};
|
||||
let wheel_collider = Collider::ball(wheel_rad);
|
||||
|
@ -149,6 +177,8 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res<AssetServer>) {
|
|||
pub struct CyberBikePlugin;
|
||||
impl Plugin for CyberBikePlugin {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue