Make dashback configurable, fix movement bugs, add double jump forward and back.
This commit is contained in:
+82
-24
@@ -19,31 +19,23 @@ pub fn apply_air_drift(
|
||||
}
|
||||
} else {
|
||||
let target_velocity =
|
||||
input.get_last_frame().movement.x.signum() * attribs.max_air_horizontal_velocity;
|
||||
let acceleration =
|
||||
input.get_last_frame().movement.x.signum() * attribs.air_acceleration_base;
|
||||
input.get_last_frame().movement.x * attribs.air_drift_max;
|
||||
let mut acceleration =
|
||||
acceleration + input.get_last_frame().movement.x * attribs.air_acceleration_stick;
|
||||
let velocity_x = velocity.x;
|
||||
if !(velocity_x * acceleration < FGi32::ZERO) {
|
||||
if acceleration > FGi32::ZERO {
|
||||
if velocity_x + acceleration > target_velocity {
|
||||
acceleration = -attribs.air_friction;
|
||||
if velocity_x + acceleration < target_velocity {
|
||||
acceleration = target_velocity - velocity_x;
|
||||
}
|
||||
if velocity_x + acceleration > attribs.max_air_horizontal_velocity {
|
||||
acceleration = attribs.max_air_horizontal_velocity - velocity_x;
|
||||
}
|
||||
}
|
||||
} else if velocity_x + acceleration < target_velocity {
|
||||
acceleration = attribs.air_friction;
|
||||
if velocity_x + acceleration > target_velocity {
|
||||
acceleration = target_velocity - velocity_x;
|
||||
}
|
||||
if velocity_x + acceleration < -attribs.max_air_horizontal_velocity {
|
||||
acceleration = -attribs.max_air_horizontal_velocity - velocity_x;
|
||||
}
|
||||
input.get_last_frame().movement.x.signum() * attribs.air_acceleration_base + input.get_last_frame().movement.x * attribs.air_acceleration_stick;
|
||||
|
||||
// Acceleration opposes velocity
|
||||
if acceleration * velocity.x < 0 {
|
||||
// do nothing
|
||||
} else {
|
||||
let predicted_vel = velocity.x + acceleration;
|
||||
let will_go_past = predicted_vel.abs() > target_velocity.abs();
|
||||
|
||||
if velocity.x.abs() < target_velocity.abs() && will_go_past {
|
||||
// Prevent overshoot
|
||||
acceleration = target_velocity - velocity.x
|
||||
} else if velocity.x.abs() > target_velocity.abs() {
|
||||
let diff = (velocity.x - target_velocity).abs();
|
||||
acceleration = velocity.x.signum() * (-(attribs.air_friction).min(diff));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,3 +52,69 @@ pub fn apply_air_motion(
|
||||
prev_translation.0 = translation.0;
|
||||
translation.0 += velocity.0;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
input::{FighterInput, FighterInputFrame},
|
||||
math::vec::FGVec2,
|
||||
};
|
||||
|
||||
fn test_attributes() -> FighterAttributes {
|
||||
FighterAttributes {
|
||||
base_walk_accel: FGi32::ZERO,
|
||||
stick_walk_accel: FGi32::ZERO,
|
||||
max_walk_vel: FGi32::ZERO,
|
||||
dash_acceleration_duration: 0,
|
||||
dash_duration: 0,
|
||||
dash_initial_velocity: FGi32::ZERO,
|
||||
base_dash_accel: FGi32::ZERO,
|
||||
stick_dash_accel: FGi32::ZERO,
|
||||
max_dash_vel: FGi32::ZERO,
|
||||
jumpsquat_duration: 0,
|
||||
short_hop_vertical_velocity: FGi32::ZERO,
|
||||
full_jump_vertical_velocity: FGi32::ZERO,
|
||||
jump_horizontal_velocity: FGi32::ZERO,
|
||||
air_jump_multiplier: FGi32::ZERO,
|
||||
air_jump_horizontal_velocity: FGi32::ZERO,
|
||||
landing_iasa: 0,
|
||||
landing_duration: 0,
|
||||
air_acceleration_base: FGi32::ZERO,
|
||||
air_acceleration_stick: FGi32::ZERO,
|
||||
max_air_horizontal_velocity: FGi32::lit("1.2"),
|
||||
air_drift_max: FGi32::lit("1.2"),
|
||||
ground_friction: FGi32::ZERO,
|
||||
terminal_velocity: FGi32::ZERO,
|
||||
gravity: FGi32::ZERO,
|
||||
weight: FGi32::lit("1"),
|
||||
air_friction: FGi32::lit("0.001"),
|
||||
air_dodge_duration: 0,
|
||||
air_dodge_velocity: FGi32::ZERO,
|
||||
air_dodge_decay: FGi32::ZERO,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zero_air_acceleration_is_symmetric() {
|
||||
let attributes = test_attributes();
|
||||
let mut right_input = FighterInput::default();
|
||||
right_input.push_input_frame(FighterInputFrame {
|
||||
movement: FGVec2::new(FGi32::ONE, FGi32::ZERO),
|
||||
..default()
|
||||
});
|
||||
let mut left_input = FighterInput::default();
|
||||
left_input.push_input_frame(FighterInputFrame {
|
||||
movement: FGVec2::new(-FGi32::ONE, FGi32::ZERO),
|
||||
..default()
|
||||
});
|
||||
|
||||
let mut right_velocity = FighterVelocity(FGVec2::ZERO);
|
||||
let mut left_velocity = FighterVelocity(FGVec2::ZERO);
|
||||
apply_air_drift(&mut right_velocity, &attributes, &right_input);
|
||||
apply_air_drift(&mut left_velocity, &attributes, &left_input);
|
||||
|
||||
assert_eq!(right_velocity.x, FGi32::ZERO);
|
||||
assert_eq!(left_velocity.x, FGi32::ZERO);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user