From 031d4815e243cf31f59511b20688aee064bb7a06 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Wed, 22 Feb 2023 22:39:48 -0800 Subject: [PATCH] fucked up --- src/action/components.rs | 4 +--- src/action/mod.rs | 1 + src/action/systems.rs | 11 ++++++++++- src/bike/body.rs | 2 +- src/bike/components.rs | 2 +- src/bike/wheels.rs | 14 ++++---------- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/action/components.rs b/src/action/components.rs index 1652477..efa3cea 100644 --- a/src/action/components.rs +++ b/src/action/components.rs @@ -46,14 +46,12 @@ impl Default for Tunneling { pub struct MovementSettings { pub accel: f32, pub gravity: f32, - pub sensitivity: f32, } impl Default for MovementSettings { fn default() -> Self { Self { - sensitivity: 6.0, - accel: 40.0, + accel: 20.0, gravity: 9.8, } } diff --git a/src/action/mod.rs b/src/action/mod.rs index af13e47..dabccf2 100644 --- a/src/action/mod.rs +++ b/src/action/mod.rs @@ -28,6 +28,7 @@ impl Plugin for CyberActionPlugin { .register_type::() .register_type::() .add_plugin(RapierPhysicsPlugin::::default()) + .add_startup_system(timestep_setup) .add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_system(surface_fix.label("surface_fix")) .add_system(gravity.label("gravity").before("cat")) diff --git a/src/action/systems.rs b/src/action/systems.rs index 09aea8f..1f29e12 100644 --- a/src/action/systems.rs +++ b/src/action/systems.rs @@ -5,7 +5,7 @@ use bevy::prelude::{ }; use bevy_rapier3d::prelude::{ CollisionGroups, ExternalForce, Group, MultibodyJoint, QueryFilter, RapierConfiguration, - RapierContext, ReadMassProperties, Velocity, + RapierContext, ReadMassProperties, TimestepMode, Velocity, }; #[cfg(feature = "inspector")] @@ -36,6 +36,15 @@ fn rotate_point(pt: &Vec3, rot: &Quat) -> Vec3 { -Vec3::from_array([rot_qpt.x, rot_qpt.y, rot_qpt.z]) } +pub(super) fn timestep_setup(mut config: ResMut) { + let ts = TimestepMode::Interpolated { + dt: 1.0 / 55.0, + time_scale: 1.0, + substeps: 16, + }; + config.timestep_mode = ts; +} + /// The gravity vector points from the cyberbike to the center of the planet. pub(super) fn gravity( mut query: Query<(&Transform, &mut ExternalForce), With>, diff --git a/src/bike/body.rs b/src/bike/body.rs index 44e4baf..533eb58 100644 --- a/src/bike/body.rs +++ b/src/bike/body.rs @@ -55,7 +55,7 @@ pub(super) fn spawn_cyberbike( .spawn(RigidBody::Dynamic) .insert(spatialbundle) .insert(( - Collider::capsule(Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8), 0.40), + Collider::capsule(Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8), 0.5), bike_collision_group, mass_properties, damping, diff --git a/src/bike/components.rs b/src/bike/components.rs index 0f8ee1b..e98f66f 100644 --- a/src/bike/components.rs +++ b/src/bike/components.rs @@ -38,7 +38,7 @@ impl Default for WheelConfig { stiffness: 50.0, damping: 8.0, radius: 0.3, - thickness: 0.06, + thickness: 0.2, friction: 1.2, restitution: 0.8, density: 0.6, diff --git a/src/bike/wheels.rs b/src/bike/wheels.rs index 555cbb9..7ee8e4c 100644 --- a/src/bike/wheels.rs +++ b/src/bike/wheels.rs @@ -76,14 +76,8 @@ pub fn spawn_tires( linear_damping: 0.8, ..Default::default() }; - let mesh = Mesh::from(tire); - let mut idxs = Vec::new(); - let indices = mesh.indices().unwrap().iter().collect::>(); - for idx in indices.as_slice().chunks_exact(3) { - idxs.push([idx[0] as u32, idx[1] as u32, idx[2] as u32]); - } - let wheel_collider = Collider::round_cylinder(tire_thickness, wheel_rad, tire_thickness); + let wheel_collider = Collider::ball(wheel_rad); let mass_props = ColliderMassProperties::Density(conf.density); let damping = conf.damping; @@ -119,11 +113,11 @@ pub fn spawn_tires( fork_rb_entity }; - let axel_builder = RevoluteJointBuilder::new(Vec3::Y); + let axel_builder = RevoluteJointBuilder::new(Vec3::X); let mut axel_joint = MultibodyJoint::new(axel_parent_entity, axel_builder); // re-orient the joint so that the wheel is correctly oriented - let real_axel = *axel_joint.data.set_local_axis1(Vec3::X); - axel_joint.data = real_axel; + //let real_axel = *axel_joint.data.set_local_axis1(Vec3::X); + //axel_joint.data = real_axel; commands.spawn(pbr_bundle.clone()).insert(( wheel_collider,