crappy thrust and yaw handling
This commit is contained in:
parent
8c16a7f9d2
commit
b5ed478dbe
2 changed files with 24 additions and 7 deletions
|
@ -44,8 +44,8 @@ impl Default for SuspensionConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
rest_dist: REST_DISTANCE,
|
rest_dist: REST_DISTANCE,
|
||||||
konstant: 800.0,
|
konstant: 1600.0,
|
||||||
damping: -100.0,
|
damping: -160.0,
|
||||||
front_attach: FRONT_ATTACH,
|
front_attach: FRONT_ATTACH,
|
||||||
rear_attach: REAR_ATTACH,
|
rear_attach: REAR_ATTACH,
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,7 +172,16 @@ mod systems {
|
||||||
>,
|
>,
|
||||||
config: Res<SuspensionConfig>,
|
config: Res<SuspensionConfig>,
|
||||||
time: Res<Time>,
|
time: Res<Time>,
|
||||||
|
input: Res<InputState>,
|
||||||
) {
|
) {
|
||||||
|
let max_thrust = 30.0;
|
||||||
|
let max_yaw = 10.0;
|
||||||
|
let mut thrust = (input.throttle * max_thrust);
|
||||||
|
if input.brake {
|
||||||
|
thrust *= -1.0;
|
||||||
|
}
|
||||||
|
let yaw = input.yaw * max_yaw;
|
||||||
|
|
||||||
let dt = time.delta().as_secs_f32();
|
let dt = time.delta().as_secs_f32();
|
||||||
let mut front_wheel_xform = None;
|
let mut front_wheel_xform = None;
|
||||||
let mut rear_wheel_xform = None;
|
let mut rear_wheel_xform = None;
|
||||||
|
@ -193,12 +202,17 @@ mod systems {
|
||||||
for hit in hits.iter() {
|
for hit in hits.iter() {
|
||||||
if let Some(ref mut xform) = front_wheel_xform {
|
if let Some(ref mut xform) = front_wheel_xform {
|
||||||
let force =
|
let force =
|
||||||
suspension_force(caster, hit, &config, &mut prev.0, dt, xform, true);
|
suspension_force(caster, hit, &config, prev.as_mut(), dt, xform, true);
|
||||||
bike_forces.apply_force_at_point(
|
bike_forces.apply_force_at_point(
|
||||||
force,
|
force,
|
||||||
caster.global_origin(),
|
caster.global_origin(),
|
||||||
bike_xform.translation,
|
bike_xform.translation,
|
||||||
);
|
);
|
||||||
|
let normal = hit.normal1;
|
||||||
|
let steering = normal.cross(*bike_xform.back()) * yaw;
|
||||||
|
let thrust = normal.cross(*bike_xform.right()) * thrust;
|
||||||
|
let total = thrust + steering;
|
||||||
|
bike_forces.apply_force_at_point(total, hit.point1, bike_xform.translation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -207,12 +221,15 @@ mod systems {
|
||||||
for hit in hits.iter() {
|
for hit in hits.iter() {
|
||||||
if let Some(ref mut xform) = rear_wheel_xform {
|
if let Some(ref mut xform) = rear_wheel_xform {
|
||||||
let force =
|
let force =
|
||||||
suspension_force(caster, hit, &config, &mut prev.0, dt, xform, false);
|
suspension_force(caster, hit, &config, prev.as_mut(), dt, xform, false);
|
||||||
bike_forces.apply_force_at_point(
|
bike_forces.apply_force_at_point(
|
||||||
force,
|
force,
|
||||||
caster.global_origin(),
|
caster.global_origin(),
|
||||||
bike_xform.translation,
|
bike_xform.translation,
|
||||||
);
|
);
|
||||||
|
let normal = hit.normal1;
|
||||||
|
let thrust = normal.cross(*bike_xform.right()) * thrust;
|
||||||
|
bike_forces.apply_force_at_point(thrust, hit.point1, bike_xform.translation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,7 +239,7 @@ mod systems {
|
||||||
caster: &ShapeCaster,
|
caster: &ShapeCaster,
|
||||||
hit: &ShapeHitData,
|
hit: &ShapeHitData,
|
||||||
config: &SuspensionConfig,
|
config: &SuspensionConfig,
|
||||||
previous_dispacement: &mut f32,
|
previous_dispacement: &mut PreviousDisplacement,
|
||||||
dt: f32,
|
dt: f32,
|
||||||
wheel_xform: &mut Transform,
|
wheel_xform: &mut Transform,
|
||||||
is_front: bool,
|
is_front: bool,
|
||||||
|
@ -238,9 +255,9 @@ mod systems {
|
||||||
let dir = caster.global_direction().as_vec3();
|
let dir = caster.global_direction().as_vec3();
|
||||||
let loc = if dist < config.rest_dist {
|
let loc = if dist < config.rest_dist {
|
||||||
let displacement = config.rest_dist - dist;
|
let displacement = config.rest_dist - dist;
|
||||||
let damper_vel = (displacement - *previous_dispacement) / dt;
|
let damper_vel = (displacement - previous_dispacement.0) / dt;
|
||||||
dbg!(damper_vel);
|
dbg!(damper_vel);
|
||||||
*previous_dispacement = displacement;
|
*previous_dispacement = PreviousDisplacement(displacement);
|
||||||
let mag = config.konstant * displacement - config.damping * damper_vel;
|
let mag = config.konstant * displacement - config.damping * damper_vel;
|
||||||
up_force = -dir * mag;
|
up_force = -dir * mag;
|
||||||
attach + (cdir * dist)
|
attach + (cdir * dist)
|
||||||
|
|
Loading…
Reference in a new issue