inputs but no steering

This commit is contained in:
Joe Ardent 2024-07-25 17:31:44 -07:00
parent ecfa9b5864
commit 2b58ac82c4
3 changed files with 7 additions and 19 deletions

View file

@ -36,7 +36,7 @@ pub struct MovementSettings {
impl Default for MovementSettings { impl Default for MovementSettings {
fn default() -> Self { fn default() -> Self {
Self { Self {
accel: 20.0, accel: 2000.0,
gravity: 9.8, gravity: 9.8,
} }
} }

View file

@ -32,7 +32,7 @@ impl Plugin for CyberActionPlugin {
.insert_resource(SubstepCount(12)) .insert_resource(SubstepCount(12))
.add_systems( .add_systems(
FixedUpdate, FixedUpdate,
(set_gravity, calculate_lean, apply_lean).chain(), (set_gravity, calculate_lean, apply_lean, apply_inputs).chain(),
); );
} }
} }

View file

@ -111,35 +111,23 @@ pub(super) fn apply_inputs(
settings: Res<MovementSettings>, settings: Res<MovementSettings>,
input: Res<InputState>, input: Res<InputState>,
time: Res<Time>, time: Res<Time>,
fork: Query<(&FixedJoint, &CyberFork), With<CyberSteering>>, mut wheels: Query<(&Transform, &mut ExternalTorque), With<CyberWheel>>,
mut hub: Query<(RigidBodyQuery, &Transform), With<CyberSteering>>,
mut braking_query: Query<(&Transform, &mut ExternalTorque), With<CyberWheel>>,
mut body_query: Query<RigidBodyQuery, (With<CyberBikeBody>, Without<CyberSteering>)>, mut body_query: Query<RigidBodyQuery, (With<CyberBikeBody>, Without<CyberSteering>)>,
) { ) {
let Ok(mut bike) = body_query.get_single_mut() else { let Ok(mut _bike) = body_query.get_single_mut() else {
bevy::log::debug!("no bike body found"); bevy::log::debug!("no bike body found");
return; return;
}; };
let dt = time.delta_seconds(); let dt = time.delta_seconds();
// brake + thrust // brake + thrust
for (xform, mut motor) in braking_query.iter_mut() { for (xform, mut torque) in wheels.iter_mut() {
let factor = input.throttle * settings.accel; let factor = input.throttle * settings.accel;
let target = dt * factor; let target = dt * factor;
let torque = target * *xform.right(); let tork = target * *xform.left();
motor.apply_torque(torque); torque.apply_torque(tork);
} }
// steering // steering
let _angle = yaw_to_angle(input.yaw);
let (mut axle, xform) = hub.single_mut();
let cur_rot = xform.rotation;
let (fork, CyberFork(axis)) = fork.single();
let new = Quat::from_axis_angle(*axis, _angle);
let diff = (new - cur_rot).to_scaled_axis();
let mut lagrange = 1.0;
fork.align_orientation(&mut axle, &mut bike, diff, &mut lagrange, 0.0, dt);
} }