From d2961bd44854deaad1db5bd84af3c474b23447bd Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Wed, 15 Feb 2023 14:36:56 -0800 Subject: [PATCH] Add axels to the wheels. --- src/action/systems.rs | 6 ++++-- src/bike/body.rs | 2 +- src/bike/wheels.rs | 20 +++++++++++++------- src/input.rs | 4 ++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/action/systems.rs b/src/action/systems.rs index c12b362..1a4e74f 100644 --- a/src/action/systems.rs +++ b/src/action/systems.rs @@ -32,7 +32,8 @@ pub(super) fn gravity( settings: Res, ) { let (xform, mut forces, mprops) = query.single_mut(); - let grav = xform.translation.normalize() * -settings.gravity * mprops.0.mass; + //let grav = xform.translation.normalize() * -settings.gravity * mprops.0.mass; + let grav = Vec3::Y * -settings.gravity * mprops.0.mass; forces.force = grav; forces.torque = Vec3::ZERO; } @@ -45,7 +46,8 @@ pub(super) fn falling_cat( #[cfg(feature = "inspector")] mut debug_instant: ResMut, ) { let (xform, mut forces, mut control_vars) = bike_query.single_mut(); - let wup = xform.translation.normalize(); + //let wup = xform.translation.normalize(); + let wup = Vec3::Y; let bike_up = xform.up(); let wright = xform.forward().cross(wup).normalize(); diff --git a/src/bike/body.rs b/src/bike/body.rs index cc70859..046a070 100644 --- a/src/bike/body.rs +++ b/src/bike/body.rs @@ -51,7 +51,7 @@ pub(super) fn spawn_cyberbike( .spawn(RigidBody::Dynamic) .insert(spatialbundle) .insert(( - Collider::capsule(Vec3::new(0.0, 0.0, -0.7), Vec3::new(0.0, 0.0, 1.0), 0.50), + Collider::capsule(Vec3::new(0.0, 0.0, -0.65), Vec3::new(0.0, 0.0, 0.8), 0.50), bike_collision_group, mass_properties, damping, diff --git a/src/bike/wheels.rs b/src/bike/wheels.rs index ebf8120..8a4eb47 100644 --- a/src/bike/wheels.rs +++ b/src/bike/wheels.rs @@ -1,7 +1,7 @@ use bevy::prelude::{shape::UVSphere as Tire, *}; use bevy_rapier3d::prelude::{ Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction, - MultibodyJoint, PrismaticJointBuilder, Restitution, RigidBody, Sleeping, + MultibodyJoint, PrismaticJointBuilder, Restitution, RevoluteJointBuilder, RigidBody, Sleeping, TransformInterpolation, }; @@ -80,19 +80,25 @@ pub fn spawn_tires( let mass_props = ColliderMassProperties::Density(0.1); let damping = conf.damping; - let prismatic = PrismaticJointBuilder::new(Vec3::Y) + let prismatic_builder = PrismaticJointBuilder::new(Vec3::Y) .local_anchor1(offset) .limits(limits) - .motor_position(-0.1, stiffness, damping); - let joint = MultibodyJoint::new(bike, prismatic); + .motor_position(limits[0], stiffness, damping); + let prismatic_joint = MultibodyJoint::new(bike, prismatic_builder); + + let fork_rb_entity = commands + .spawn(RigidBody::Dynamic) + .insert(prismatic_joint) + .id(); + + let revolute_builder = RevoluteJointBuilder::new(Vec3::X); + let axel_joint = MultibodyJoint::new(fork_rb_entity, revolute_builder); let spatial_bundle = SpatialBundle { - transform: wheel_pos_in_world, ..Default::default() }; let tire_spundle = SpatialBundle { - transform: Transform::IDENTITY, ..Default::default() }; @@ -105,7 +111,7 @@ pub fn spawn_tires( wheel_damping, ccd, not_sleeping, - joint, + axel_joint, wheels_collision_group, friction, CyberWheel, diff --git a/src/input.rs b/src/input.rs index 6f614fb..c949eb9 100644 --- a/src/input.rs +++ b/src/input.rs @@ -16,8 +16,8 @@ fn update_debug_cam(mut offset: ResMut, mut keys: ResMut offset.rot += 5.0, - KeyCode::Right => offset.rot -= 5.0, + KeyCode::Left => offset.rot -= 5.0, + KeyCode::Right => offset.rot += 5.0, KeyCode::Up => { if shifted { offset.alt += 0.5;