Skip to content

Commit

Permalink
it works!
Browse files Browse the repository at this point in the history
  • Loading branch information
alexichepura committed Jul 19, 2024
1 parent 7fe1326 commit 7371f45
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions car/src/esp.rs
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
use bevy::prelude::*;
use bevy::{color::palettes::css, prelude::*};
use bevy_rapier3d::prelude::*;
use std::f32::consts::PI;

Expand Down Expand Up @@ -117,7 117,7 @@ pub fn esp_system(
if car_res.show_rays {
let start = transform.translation WHEEL_RAY_SHIFT;
let end = start WHEEL_RAY_END_QUAT.mul_vec3(f.torque) / 200.;
gizmos.line(start, end, Color::BLACK);
gizmos.line(start, end, css::VIOLET);
}

j.data.as_mut().set_local_basis1(quat);
Expand Down
46 changes: 23 additions & 23 deletions examples/plane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 3,14 @@ use bevy_garage_car::{car_start_system, esp_system, spawn_car, Car, CarRes};
use bevy_rapier3d::prelude::*;

fn main() {
let mut rapier_config = RapierConfiguration::new(1.);
rapier_config.timestep_mode = TimestepMode::Variable {
max_dt: 1. / 60.,
time_scale: 1.,
substeps: 5,
};
App::new()
.insert_resource(RapierConfiguration {
timestep_mode: TimestepMode::Variable {
max_dt: 1. / 60.,
time_scale: 1.,
substeps: 10,
},
..default()
})
.insert_resource(rapier_config)
.add_plugins((
DefaultPlugins,
RapierPhysicsPlugin::<NoUserData>::default(),
Expand All @@ -35,10 34,10 @@ fn main() {
}

fn rapier_config_start_system(mut c: ResMut<RapierContext>) {
c.integration_parameters.max_velocity_iterations = 64;
c.integration_parameters.max_velocity_friction_iterations = 64;
c.integration_parameters.max_stabilization_iterations = 16;
c.integration_parameters.erp = 0.99;
// c.integration_parameters.max_velocity_iterations = 64;
// c.integration_parameters.max_velocity_friction_iterations = 64;
// c.integration_parameters.max_stabilization_iterations = 16;
// c.integration_parameters.erp = 0.99;
}

fn spawn_car_system(mut cmd: Commands, car_res: Res<CarRes>) {
Expand All @@ -62,10 61,11 @@ fn plane_start(
) {
let size = 100.;
let (cols, rows) = (10, 10);

cmd.spawn((
PbrBundle {
mesh: meshes.add(shape::Plane::from_size(size).into()),
material: materials.add(Color::rgb(0.3, 0.5, 0.3).into()),
mesh: meshes.add(Plane3d::default().mesh().size(size, size)),
material: materials.add(Color::srgb(0.3, 0.5, 0.3)),
..default()
},
RigidBody::Fixed,
Expand All @@ -91,32 91,32 @@ fn plane_start(
});
}

fn input_system(input: Res<Input<KeyCode>>, mut cars: Query<&mut Car>) {
fn input_system(input: Res<ButtonInput<KeyCode>>, mut cars: Query<&mut Car>) {
for mut car in cars.iter_mut() {
if input.pressed(KeyCode::Up) {
if input.pressed(KeyCode::ArrowUp) {
car.gas = 1.;
}
if input.just_released(KeyCode::Up) {
if input.just_released(KeyCode::ArrowUp) {
car.gas = 0.;
}

if input.pressed(KeyCode::Down) {
if input.pressed(KeyCode::ArrowDown) {
car.brake = 1.;
}
if input.just_released(KeyCode::Down) {
if input.just_released(KeyCode::ArrowDown) {
car.brake = 0.;
}

if input.pressed(KeyCode::Left) {
if input.pressed(KeyCode::ArrowLeft) {
car.steering = -1.;
}
if input.pressed(KeyCode::Right) {
if input.pressed(KeyCode::ArrowRight) {
car.steering = 1.;
}
if input.just_released(KeyCode::Left) {
if input.just_released(KeyCode::ArrowLeft) {
car.steering = 0.;
}
if input.just_released(KeyCode::Right) {
if input.just_released(KeyCode::ArrowRight) {
car.steering = 0.;
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/dash.rs
Original file line number Diff line number Diff line change
@@ -1,4 1,5 @@
use bevy::{
color::palettes::css,
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
prelude::*,
};
Expand Down Expand Up @@ -52,7 53,7 @@ pub fn dash_start_system(mut cmd: Commands, asset_server: Res<AssetServer>) {
..default()
})
.with_children(|parent| {
let background_color: BackgroundColor = Color::rgba(0.15, 0.15, 0.15, 0.5).into();
let background_color: BackgroundColor = Color::srgba(0.15, 0.15, 0.15, 0.5).into();
parent
.spawn(NodeBundle {
background_color,
Expand Down Expand Up @@ -82,7 83,7 @@ pub fn dash_start_system(mut cmd: Commands, asset_server: Res<AssetServer>) {
style: TextStyle {
font: medium.clone(),
font_size: 16.0,
color: Color::YELLOW_GREEN,
color: css::YELLOW_GREEN.into(),
},
}],
..default()
Expand All @@ -104,7 105,7 @@ pub fn dash_start_system(mut cmd: Commands, asset_server: Res<AssetServer>) {
style: TextStyle {
font: medium.clone(),
font_size: 18.0,
color: Color::SALMON,
color: css::SALMON.into(),
},
}],
..default()
Expand All @@ -127,7 128,7 @@ pub fn dash_start_system(mut cmd: Commands, asset_server: Res<AssetServer>) {
style: TextStyle {
font: medium.clone(),
font_size: 16.0,
color: Color::YELLOW,
color: css::YELLOW.into(),
},
}],
..default()
Expand All @@ -144,7 145,7 @@ pub fn dash_start_system(mut cmd: Commands, asset_server: Res<AssetServer>) {
style: TextStyle {
font: medium.clone(),
font_size: 18.0,
color: Color::YELLOW,
color: css::YELLOW.into(),
},
}],
..default()
Expand All @@ -161,7 162,7 @@ pub fn dash_start_system(mut cmd: Commands, asset_server: Res<AssetServer>) {
style: TextStyle {
font: medium.clone(),
font_size: 24.0,
color: Color::YELLOW_GREEN,
color: css::YELLOW_GREEN.into(),
},
}],
..default()
Expand All @@ -177,7 178,7 @@ pub fn dash_start_system(mut cmd: Commands, asset_server: Res<AssetServer>) {
style: TextStyle {
font: medium.clone(),
font_size: 24.0,
color: Color::YELLOW,
color: css::YELLOW.into(),
},
}],
..default()
Expand Down
19 changes: 9 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,8 @@ fn rapier_config_start_system(mut c: ResMut<RapierContext>) {
c.integration_parameters.num_solver_iterations = NonZeroUsize::new(4).unwrap();
c.integration_parameters.num_internal_pgs_iterations = 48;
c.integration_parameters.num_additional_friction_iterations = 4;
c.integration_parameters.erp = 0.99;
// c.integration_parameters.erp = 0.99;
// c.integration_parameters.joint_natural_frequency
// c.integration_parameters.joint_erp = 0.95;
dbg!(c.integration_parameters);
}
Expand All @@ -34,16 35,14 @@ pub fn car_app(app: &mut App) -> &mut App {
#[cfg(not(feature = "nn"))]
let esp_run_after: CarSet = CarSet::Input;

let mut rapier_config = RapierConfiguration::new(1.);
rapier_config.timestep_mode = TimestepMode::Variable {
max_dt: 1. / 60.,
time_scale: 1.,
substeps: 5,
};
app.init_resource::<FontHandle>()
.insert_resource(RapierConfiguration {
// https://github.com/dimforge/bevy_rapier/pull/474
timestep_mode: TimestepMode::Variable {
max_dt: 1. / 60.,
time_scale: 1.,
substeps: 5,
},
..default()
})
.insert_resource(rapier_config)
.insert_resource(Msaa::Sample4)
.insert_resource(Config::default())
.insert_resource(CarRes::default())
Expand Down

0 comments on commit 7371f45

Please sign in to comment.