Add axels to the wheels.

This commit is contained in:
Joe Ardent 2023-02-15 14:36:56 -08:00
parent 421f34fab7
commit d2961bd448
4 changed files with 20 additions and 12 deletions

View file

@ -32,7 +32,8 @@ pub(super) fn gravity(
settings: Res<MovementSettings>, settings: Res<MovementSettings>,
) { ) {
let (xform, mut forces, mprops) = query.single_mut(); 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.force = grav;
forces.torque = Vec3::ZERO; forces.torque = Vec3::ZERO;
} }
@ -45,7 +46,8 @@ pub(super) fn falling_cat(
#[cfg(feature = "inspector")] mut debug_instant: ResMut<ActionDebugInstant>, #[cfg(feature = "inspector")] mut debug_instant: ResMut<ActionDebugInstant>,
) { ) {
let (xform, mut forces, mut control_vars) = bike_query.single_mut(); 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 bike_up = xform.up();
let wright = xform.forward().cross(wup).normalize(); let wright = xform.forward().cross(wup).normalize();

View file

@ -51,7 +51,7 @@ pub(super) fn spawn_cyberbike(
.spawn(RigidBody::Dynamic) .spawn(RigidBody::Dynamic)
.insert(spatialbundle) .insert(spatialbundle)
.insert(( .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, bike_collision_group,
mass_properties, mass_properties,
damping, damping,

View file

@ -1,7 +1,7 @@
use bevy::prelude::{shape::UVSphere as Tire, *}; use bevy::prelude::{shape::UVSphere as Tire, *};
use bevy_rapier3d::prelude::{ use bevy_rapier3d::prelude::{
Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction, Ccd, Collider, ColliderMassProperties, CollisionGroups, Damping, ExternalForce, Friction,
MultibodyJoint, PrismaticJointBuilder, Restitution, RigidBody, Sleeping, MultibodyJoint, PrismaticJointBuilder, Restitution, RevoluteJointBuilder, RigidBody, Sleeping,
TransformInterpolation, TransformInterpolation,
}; };
@ -80,19 +80,25 @@ pub fn spawn_tires(
let mass_props = ColliderMassProperties::Density(0.1); let mass_props = ColliderMassProperties::Density(0.1);
let damping = conf.damping; let damping = conf.damping;
let prismatic = PrismaticJointBuilder::new(Vec3::Y) let prismatic_builder = PrismaticJointBuilder::new(Vec3::Y)
.local_anchor1(offset) .local_anchor1(offset)
.limits(limits) .limits(limits)
.motor_position(-0.1, stiffness, damping); .motor_position(limits[0], stiffness, damping);
let joint = MultibodyJoint::new(bike, prismatic); 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 { let spatial_bundle = SpatialBundle {
transform: wheel_pos_in_world,
..Default::default() ..Default::default()
}; };
let tire_spundle = SpatialBundle { let tire_spundle = SpatialBundle {
transform: Transform::IDENTITY,
..Default::default() ..Default::default()
}; };
@ -105,7 +111,7 @@ pub fn spawn_tires(
wheel_damping, wheel_damping,
ccd, ccd,
not_sleeping, not_sleeping,
joint, axel_joint,
wheels_collision_group, wheels_collision_group,
friction, friction,
CyberWheel, CyberWheel,

View file

@ -16,8 +16,8 @@ fn update_debug_cam(mut offset: ResMut<DebugCamOffset>, mut keys: ResMut<Input<K
for key in keyset { for key in keyset {
match key { match key {
KeyCode::Left => offset.rot += 5.0, KeyCode::Left => offset.rot -= 5.0,
KeyCode::Right => offset.rot -= 5.0, KeyCode::Right => offset.rot += 5.0,
KeyCode::Up => { KeyCode::Up => {
if shifted { if shifted {
offset.alt += 0.5; offset.alt += 0.5;