still gets unstable

This commit is contained in:
Joe Ardent 2023-02-23 22:08:08 -08:00
parent 708b518047
commit 2db6041774
5 changed files with 36 additions and 31 deletions

View File

@ -49,8 +49,18 @@ pub(super) fn gravity(
mut query: Query<(&Transform, &mut ExternalForce), With<CyberBikeBody>>, mut query: Query<(&Transform, &mut ExternalForce), With<CyberBikeBody>>,
settings: Res<MovementSettings>, settings: Res<MovementSettings>,
mut rapier_config: ResMut<RapierConfiguration>, mut rapier_config: ResMut<RapierConfiguration>,
#[cfg(feature = "inspector")] mut debug_instant: ResMut<ActionDebugInstant>,
) { ) {
let (xform, mut forces) = query.single_mut(); let (xform, mut forces) = query.single_mut();
#[cfg(feature = "inspector")]
{
if debug_instant.elapsed().as_millis() > 1000 {
dbg!(&forces);
debug_instant.reset();
}
}
rapier_config.gravity = xform.translation.normalize() * -settings.gravity; rapier_config.gravity = xform.translation.normalize() * -settings.gravity;
forces.force = Vec3::ZERO; forces.force = Vec3::ZERO;
forces.torque = Vec3::ZERO; forces.torque = Vec3::ZERO;
@ -88,7 +98,6 @@ pub(super) fn falling_cat(
time: Res<Time>, time: Res<Time>,
settings: Res<CatControllerSettings>, settings: Res<CatControllerSettings>,
lean: Res<CyberLean>, lean: Res<CyberLean>,
#[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 world_up = xform.translation.normalize(); let world_up = xform.translation.normalize();
@ -108,13 +117,6 @@ pub(super) fn falling_cat(
if mag.is_finite() { if mag.is_finite() {
forces.torque += xform.back() * mag; forces.torque += xform.back() * mag;
} }
#[cfg(feature = "inspector")]
{
if debug_instant.elapsed().as_millis() > 1000 {
dbg!(&control_vars, mag, &target_up);
debug_instant.reset();
}
}
} }
} }

View File

@ -16,7 +16,7 @@ pub(super) fn spawn_cyberbike(
wheel_conf: Res<WheelConfig>, wheel_conf: Res<WheelConfig>,
mut meshterials: Meshterial, mut meshterials: Meshterial,
) { ) {
let altitude = PLANET_RADIUS - 180.0; let altitude = PLANET_RADIUS - 10.0;
let mut xform = Transform::from_translation(Vec3::X * altitude) let mut xform = Transform::from_translation(Vec3::X * altitude)
.with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians())); .with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians()));

View File

@ -37,11 +37,11 @@ impl Default for WheelConfig {
limits: [-0.5, 0.1], limits: [-0.5, 0.1],
stiffness: 50.0, stiffness: 50.0,
damping: 8.0, damping: 8.0,
radius: 0.3, radius: 0.38,
thickness: 0.2, thickness: 0.2,
friction: 1.2, friction: 1.2,
restitution: 0.8, restitution: 0.95,
density: 0.6, density: 0.9,
} }
} }
} }

View File

@ -17,7 +17,7 @@ pub fn spawn_tires(
let wheels_collision_group = CollisionGroups::new(membership, filter); let wheels_collision_group = CollisionGroups::new(membership, filter);
let wheel_y = conf.y; let wheel_y = conf.y;
let wheel_rad = conf.radius; let wheel_rad = conf.radius;
let tire_thickness = conf.thickness; let _tire_thickness = conf.thickness;
let stiffness = conf.stiffness; let stiffness = conf.stiffness;
let not_sleeping = Sleeping::disabled(); let not_sleeping = Sleeping::disabled();
let ccd = Ccd { enabled: true }; let ccd = Ccd { enabled: true };
@ -100,7 +100,7 @@ pub fn spawn_tires(
let axel_parent_entity = if let Some(steering) = steering { let axel_parent_entity = if let Some(steering) = steering {
let neck_builder = let neck_builder =
RevoluteJointBuilder::new(rake_vec).local_anchor1(Vec3::new(0.0, 0.0, 0.1)); // this adds another 0.1m of trail RevoluteJointBuilder::new(rake_vec).local_anchor1(Vec3::new(0.0, -0.08, 0.1)); // this adds another 0.1m of trail
let neck_joint = MultibodyJoint::new(fork_rb_entity, neck_builder); let neck_joint = MultibodyJoint::new(fork_rb_entity, neck_builder);
let neck = commands let neck = commands
.spawn(RigidBody::Dynamic) .spawn(RigidBody::Dynamic)
@ -114,25 +114,28 @@ pub fn spawn_tires(
}; };
let axel_builder = RevoluteJointBuilder::new(Vec3::X); let axel_builder = RevoluteJointBuilder::new(Vec3::X);
let mut axel_joint = MultibodyJoint::new(axel_parent_entity, axel_builder); let axel_joint = MultibodyJoint::new(axel_parent_entity, axel_builder);
// re-orient the joint so that the wheel is correctly oriented // re-orient the joint so that the wheel is correctly oriented
//let real_axel = *axel_joint.data.set_local_axis1(Vec3::X); //let real_axel = *axel_joint.data.set_local_axis1(Vec3::X);
//axel_joint.data = real_axel; //axel_joint.data = real_axel;
commands.spawn(pbr_bundle.clone()).insert(( commands
wheel_collider, .spawn(pbr_bundle.clone())
mass_props, .insert((
wheel_damping, wheel_collider,
ccd, mass_props,
not_sleeping, wheel_damping,
axel_joint, ccd,
wheels_collision_group, not_sleeping,
friction, axel_joint,
CyberWheel, wheels_collision_group,
ExternalForce::default(), friction,
Restitution::new(conf.restitution), CyberWheel,
TransformInterpolation::default(), ExternalForce::default(),
RigidBody::Dynamic, Restitution::new(conf.restitution),
)); TransformInterpolation::default(),
RigidBody::Dynamic,
))
.insert(SpatialBundle::default());
} }
} }

View File

@ -9,7 +9,7 @@ use wgpu::PrimitiveTopology;
use crate::Label; use crate::Label;
pub const PLANET_RADIUS: f32 = 6000.0; pub const PLANET_RADIUS: f32 = 3_000.0;
#[derive(Component)] #[derive(Component)]
pub struct CyberPlanet; pub struct CyberPlanet;