diff --git a/Cargo.lock b/Cargo.lock index 3a69ae8..a0cc2cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -461,7 +461,8 @@ dependencies = [ [[package]] name = "bevy_rapier3d" version = "0.12.1" -source = "git+https://github.com/nebkor/bevy_rapier?branch=debug-render-capsule#3387b8ff9d3615033144cb2e22ad4a965caa6b2b" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5186c735d7aa202e982f93c71b444d34bf15fed44aca942f9b5f2940e3d06764" dependencies = [ "bevy", "nalgebra", @@ -2599,9 +2600,9 @@ checksum = "8fb1df15f412ee2e9dfc1c504260fa695c1c3f10fe9f4a6ee2d2184d7d6450e2" [[package]] name = "syn" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a65b3f4ffa0092e9887669db0eae07941f023991ab58ea44da8fe8e2d511c6b" +checksum = "1e59d925cf59d8151f25a3bedf97c9c157597c9df7324d32d68991cc399ed08b" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 5f5f031..55ffb65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,11 +26,11 @@ features = [ ] [dependencies.bevy_rapier3d] -git = "https://github.com/nebkor/bevy_rapier" +#git = "https://github.com/nebkor/bevy_rapier" #path = "../bevy_rapier/bevy_rapier3d" -branch = "debug-render-capsule" +#branch = "debug-render-capsule" features = ["simd-nightly"] -# version = "0.12" +version = "0.12" # Maybe also enable only a small amount of optimization for our code: [profile.dev] diff --git a/src/action.rs b/src/action.rs index a37bf6e..6c1a799 100644 --- a/src/action.rs +++ b/src/action.rs @@ -39,11 +39,20 @@ fn falling_cat( let cam_up = bike_xform.up(); let cos = up.dot(cam_up); + let roll_cos = up.dot(bike_xform.right()); + + let r_mag = if roll_cos.is_normal() { + roll_cos.powi(3) * 8.0 + } else { + 0.0 + }; + let r_tork = bike_xform.forward() * r_mag; + let theta = cos.acos(); - let force_mag = if !theta.is_normal() { 0.0 } else { theta * 2.0 }; + let force_mag = if !theta.is_normal() { 0.0 } else { theta * 7.0 }; let torque = cam_up.cross(up).normalize() * force_mag; - forces.torque = torque.into(); + forces.torque = (r_tork + torque).into(); } fn drag( @@ -56,7 +65,7 @@ fn drag( if let Some(vel) = vels.linvel.try_normalize(0.001) { let v2 = vels.linvel.magnitude_squared(); - forces.force -= vel * v2 * 0.002; + forces.force -= vel * v2 * 0.02; } } diff --git a/src/bike.rs b/src/bike.rs index 80eaa5f..7612b24 100644 --- a/src/bike.rs +++ b/src/bike.rs @@ -3,7 +3,7 @@ use bevy_rapier3d::prelude::*; use crate::planet::PLANET_RADIUS; -pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 1.015 + 90.0; +pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS * 1.01; #[derive(Component)] pub struct CyberBikeBody; @@ -14,9 +14,12 @@ pub struct CyberBikeCollider; #[derive(Component, Debug)] pub struct CyberBikeModel; +const BIKE_BODY_GROUP: InteractionGroups = InteractionGroups::new(0b01, 0b01); +const BIKE_WHEEL_GROUP: InteractionGroups = InteractionGroups::new(0b10, 0b10); + fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { - let xform = Transform::from_translation(Vec3::Y * SPAWN_ALTITUDE) - .with_rotation(Quat::from_axis_angle(Vec3::X, -80.0f32.to_radians())); + let xform = Transform::from_translation(Vec3::X * SPAWN_ALTITUDE) + .with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians())); let mut bbody = RigidBodyBundle::default(); @@ -42,7 +45,12 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { ); let bcollide = ColliderBundle { shape: shape.into(), - mass_properties: ColliderMassProps::Density(0.04).into(), + mass_properties: ColliderMassProps::Density(0.82).into(), + flags: ColliderFlags { + collision_groups: BIKE_BODY_GROUP, + ..Default::default() + } + .into(), material: ColliderMaterial { friction: 0.0, restitution: 0.0, @@ -73,18 +81,24 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { .id(); // seriously the cyberbike is so fucking huge what the heck - let wheel_positions = vec![-5.5, 4.7]; - let wheel_rad = 0.7; - let wheel_y = -2.0; + let wheel_positions = vec![-5.1, 4.7, 4.7, -5.1]; + let wheel_rad = 1.55; + let wheel_y = -1.5f32; - for wheel_z in wheel_positions { - let offset = Vec3::new(0.0, wheel_y, wheel_z); + for (i, &wheel_z) in wheel_positions.iter().enumerate() { + let wheel_x = if i % 2 == 0 { -2.5 } else { 2.5 }; + let offset = Vec3::new(wheel_x, wheel_y, wheel_z); let trans = xform.translation + offset; let wheel_pos_in_world = Isometry::from_parts(trans.into(), xform.rotation.into()); let _wheel_rb = commands .spawn_bundle(RigidBodyBundle { position: wheel_pos_in_world.into(), activation: RigidBodyActivation::cannot_sleep().into(), + damping: RigidBodyDamping { + angular_damping: 0.8, + ..Default::default() + } + .into(), ccd: RigidBodyCcd { ccd_enabled: true, ccd_max_dist: wheel_rad, @@ -97,18 +111,23 @@ fn spawn_cyberbike(mut commands: Commands, asset_server: Res) { .insert_bundle(ColliderBundle { material: ColliderMaterial::new(0.0, 0.0).into(), shape: ColliderShape::ball(wheel_rad).into(), - mass_properties: ColliderMassProps::Density(0.01).into(), + mass_properties: ColliderMassProps::Density(0.001).into(), + flags: ColliderFlags { + collision_groups: BIKE_WHEEL_GROUP, + ..Default::default() + } + .into(), ..Default::default() }) .insert(ColliderPositionSync::Discrete) .insert(ColliderDebugRender::from(Color::YELLOW)) .id(); - let (stiffness, damping) = (0.1, 0.4); + let (stiffness, damping) = (0.011, 0.25); let prismatic = PrismaticJoint::new(Vector::y_axis()) .local_anchor1(offset.into()) - .motor_position(-0.1, stiffness, damping); + .motor_position(-0.2, stiffness, damping); commands.spawn_bundle(((JointBuilderComponent::new(prismatic, bike, _wheel_rb)),)); } diff --git a/src/camera.rs b/src/camera.rs index 39ff72a..86c1c3c 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -114,7 +114,7 @@ pub struct CyberCamPlugin; impl Plugin for CyberCamPlugin { fn build(&self, app: &mut bevy::prelude::App) { app.add_startup_system(setup_cybercams) - .add_state(CyberCameras::Debug) + .add_state(CyberCameras::Hero) .add_system(cycle_cam_state) .add_system(update_active_camera) .add_system(follow_cyberbike); diff --git a/src/main.rs b/src/main.rs index ddcd75e..3e5ca2c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,9 +12,9 @@ use cyber_rider::{ }; const MOVEMENT_SETTINGS: MovementSettings = MovementSettings { - sensitivity: 10.0, // steering - accel: 30.0, // thrust - gravity: 8.0, + sensitivity: 60.0, // steering + accel: 70.0, // thrust + gravity: 7.0, }; fn main() {