Implement double jumping and RoA style wavedash

This commit is contained in:
2026-08-27 16:36:36 +02:00
parent de73451615
commit 6a2801add0
10 changed files with 169 additions and 47 deletions
+5 -2
View File
@@ -5,7 +5,7 @@
base_walk_accel: "0.1", base_walk_accel: "0.1",
stick_walk_accel: "0.16", stick_walk_accel: "0.16",
max_walk_vel: "0.7", max_walk_vel: "0.7",
ground_friction: "0.09", ground_friction: "0.02",
dash_acceleration_duration: 13, dash_acceleration_duration: 13,
dash_duration: 24, dash_duration: 24,
base_dash_accel: "0.02", base_dash_accel: "0.02",
@@ -14,10 +14,12 @@
short_hop_vertical_velocity: "1.05", short_hop_vertical_velocity: "1.05",
full_jump_vertical_velocity: "1.6", full_jump_vertical_velocity: "1.6",
jump_horizontal_velocity: "0.7", jump_horizontal_velocity: "0.7",
air_jump_horizontal_velocity: "0.5",
air_jump_multiplier: "1.0",
dash_initial_velocity: "1.4", dash_initial_velocity: "1.4",
terminal_velocity: "1.3", terminal_velocity: "1.3",
gravity: "0.064", gravity: "0.064",
jumpsquat_duration: 4, jumpsquat_duration: 5,
landing_iasa: 4, landing_iasa: 4,
landing_duration: 30, landing_duration: 30,
@@ -40,5 +42,6 @@
JumpBack: "PlyPurin5K_Share_ACTION_JumpB", JumpBack: "PlyPurin5K_Share_ACTION_JumpB",
Landing: "PlyPurin5K_Share_ACTION_Landing", Landing: "PlyPurin5K_Share_ACTION_Landing",
AirDodge: "PlyPurin5K_Share_ACTION_EscapeAir", AirDodge: "PlyPurin5K_Share_ACTION_EscapeAir",
DoubleJump: "PlyPurin5K_Share_ACTION_JumpAerialF1",
} }
) )
+1 -1
View File
@@ -1,6 +1,6 @@
( (
input_common: ( input_common: (
stick_deadzone: "0.28", stick_deadzone: "0.275",
trigger_deadzone: "0.3", trigger_deadzone: "0.3",
smash_input_reset_axis_threshold: "0.25", smash_input_reset_axis_threshold: "0.25",
smash_input_axis_threshold: "0.8", smash_input_axis_threshold: "0.8",
+1
View File
@@ -88,6 +88,7 @@ pub enum AnimKind {
JumpSquat, JumpSquat,
JumpForward, JumpForward,
JumpBack, JumpBack,
DoubleJump,
Landing, Landing,
AirDodge, AirDodge,
} }
+2
View File
@@ -24,6 +24,8 @@ pub struct FighterAttributes {
pub short_hop_vertical_velocity: FGi32, pub short_hop_vertical_velocity: FGi32,
pub full_jump_vertical_velocity: FGi32, pub full_jump_vertical_velocity: FGi32,
pub jump_horizontal_velocity: FGi32, pub jump_horizontal_velocity: FGi32,
pub air_jump_multiplier: FGi32,
pub air_jump_horizontal_velocity: FGi32,
pub landing_iasa: u32, pub landing_iasa: u32,
pub landing_duration: u32, pub landing_duration: u32,
+33 -10
View File
@@ -2,15 +2,25 @@ use std::time::Duration;
use bevy::prelude::*; use bevy::prelude::*;
use crate::{fighter::{ use crate::{
animation::AnimKind, collision, state::{ fighter::{
FighterState, FighterStateContext, FighterStateImpl, air, dash, fall::FallState, ground::{self, GroundedMotionResult, GroundedStateCommon}, land::LandingState, wait::WaitState, walk, animation::AnimKind,
collision,
state::{
FighterState, FighterStateContext, FighterStateImpl, air, dash,
fall::FallState,
ground::{self, GroundedMotionResult, GroundedStateCommon},
land::LandingState,
wait::WaitState,
walk,
}, },
}, input}; }, input, math::vec::FGVec2,
};
#[derive(Debug, Clone, Hash)] #[derive(Debug, Clone, Hash)]
pub struct AirDodgeState { pub struct AirDodgeState {
pub duration_counter: u32, pub duration_counter: u32,
pub direction: FGVec2,
} }
impl FighterStateImpl for AirDodgeState { impl FighterStateImpl for AirDodgeState {
@@ -46,7 +56,10 @@ impl FighterStateImpl for AirDodgeState {
let grounded_common = GroundedStateCommon { let grounded_common = GroundedStateCommon {
current_line_id: res.line_id, current_line_id: res.line_id,
}; };
Some(FighterState::Land(LandingState { grounded_common, duration_counter: 0 })) Some(FighterState::Land(LandingState {
grounded_common,
duration_counter: 0,
}))
} else { } else {
None None
} }
@@ -59,12 +72,22 @@ impl FighterStateImpl for AirDodgeState {
Duration::ZERO, Duration::ZERO,
); );
state_context.velocity.0 = state_context.input.get_last_frame().movement.normalize_or_zero() * state_context.fighter_attribs.air_dodge_velocity; state_context.velocity.0 = self.direction * state_context.fighter_attribs.air_dodge_velocity;
} }
} }
pub fn check_input(state_context: &FighterStateContext) -> Option<FighterState> { pub fn check_input(state_context: &FighterStateContext) -> Option<FighterState> {
state_context.input.has_command(input::FighterCommands::Shield).then(|| state_context
FighterState::AirDodge(AirDodgeState { duration_counter: 0 }) .input
) .has_command(input::FighterCommands::Shield)
} .then(|| {
FighterState::AirDodge(AirDodgeState {
duration_counter: 0,
direction: state_context
.input
.get_last_frame()
.movement
.normalize_or_zero(),
})
})
}
+8 -3
View File
@@ -2,7 +2,7 @@
use super::{FighterStateContext, FighterStateImpl}; use super::{FighterStateContext, FighterStateImpl};
use crate::fighter::state::ground::GroundedStateCommon; use crate::fighter::state::ground::GroundedStateCommon;
use crate::fighter::state::land::LandingState; use crate::fighter::state::land::LandingState;
use crate::fighter::state::{FighterState, air}; use crate::fighter::state::{FighterState, air, jump};
use crate::fighter::collision; use crate::fighter::collision;
#[derive(Debug, Clone, Copy, Hash)] #[derive(Debug, Clone, Copy, Hash)]
@@ -10,14 +10,19 @@ pub struct FallState;
impl FighterStateImpl for FallState { impl FighterStateImpl for FallState {
const NAME: &'static str = "Fall"; const NAME: &'static str = "Fall";
fn check_interrupt(&self, _state_context: &FighterStateContext) -> Option<FighterState> { fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
None jump::check_input_double_jump(state_context)
} }
fn on_enter(&mut self, _state_context: &mut super::FighterStateContext) {} fn on_enter(&mut self, _state_context: &mut super::FighterStateContext) {}
fn update(&mut self, state_context: &mut super::FighterStateContext) { fn update(&mut self, state_context: &mut super::FighterStateContext) {
air::integrate_gravity(state_context.velocity, state_context.fighter_attribs); air::integrate_gravity(state_context.velocity, state_context.fighter_attribs);
air::apply_air_drift(
state_context.velocity,
state_context.fighter_attribs,
state_context.input,
);
air::apply_air_motion( air::apply_air_motion(
state_context.velocity, state_context.velocity,
state_context.translation, state_context.translation,
+115 -29
View File
@@ -4,10 +4,18 @@ use bevy::prelude::*;
use crate::{ use crate::{
fighter::{ fighter::{
animation::AnimKind, collision, state::{ animation::AnimKind,
FighterState, FighterStateContext, FighterStateImpl, air, air_dodge, fall::FallState, ground::{self, GroundedMotionResult, GroundedStateCommon}, land::LandingState, collision,
state::{
FighterState, FighterStateContext, FighterStateImpl, air,
air_dodge::{self, AirDodgeState},
fall::FallState,
ground::{self, GroundedMotionResult, GroundedStateCommon},
land::LandingState,
}, },
}, input::FighterCommands, },
input::FighterCommands,
math::{int::FGi32, vec::FGVec2},
}; };
#[derive(Debug, Hash, Clone, Copy)] #[derive(Debug, Hash, Clone, Copy)]
pub enum JumpType { pub enum JumpType {
@@ -18,7 +26,7 @@ pub enum JumpType {
#[derive(Debug, Clone, Hash)] #[derive(Debug, Clone, Hash)]
pub struct JumpState { pub struct JumpState {
jump_type: JumpType jump_type: JumpType,
} }
#[derive(Debug, Clone, Hash)] #[derive(Debug, Clone, Hash)]
@@ -40,10 +48,37 @@ impl FighterStateImpl for JumpSquatState {
const NAME: &'static str = "JumpSquat"; const NAME: &'static str = "JumpSquat";
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> { fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
if self.duration_counter >= state_context.fighter_attribs.jumpsquat_duration { // Special handling for wavedash from jump squat
if state_context.input.has_command(FighterCommands::Shield) {
// If aiming sideways and in the deadzone, do a perfect wavedash
let mut wavedash_dir = state_context
.input
.get_last_frame()
.movement
.normalize_or_zero();
let movement = state_context.input.get_last_frame().movement;
if movement.y.is_zero() && !movement.x.is_zero() {
wavedash_dir.y =
-state_context.game_settings.input_common.stick_deadzone - FGi32::lit("-0.01");
wavedash_dir.x = movement.x.signum();
}
if wavedash_dir == FGVec2::ZERO {
wavedash_dir = FGVec2::lit("0.0", "-1.0");
}
Some(FighterState::AirDodge(AirDodgeState {
duration_counter: 0,
direction: wavedash_dir.normalize_or_zero(),
}))
} else if self.duration_counter >= state_context.fighter_attribs.jumpsquat_duration {
info!("Jump {}", state_context.input.get_last_frame().jump); info!("Jump {}", state_context.input.get_last_frame().jump);
let jump_type = if state_context.input.get_last_frame().jump {JumpType::LongJump} else {JumpType::ShortHop}; let jump_type = if state_context.input.get_last_frame().jump {
Some(FighterState::Jump(JumpState { jump_type})) JumpType::LongJump
} else {
JumpType::ShortHop
};
Some(FighterState::Jump(JumpState { jump_type }))
} else { } else {
None None
} }
@@ -93,54 +128,91 @@ impl FighterStateImpl for JumpSquatState {
state_context.animations.clips[&AnimKind::JumpSquat], state_context.animations.clips[&AnimKind::JumpSquat],
Duration::ZERO, Duration::ZERO,
); );
state_context.input.clear_buffer(); state_context.input.clear_command(FighterCommands::Jump);
} }
} }
impl FighterStateImpl for JumpState { impl FighterStateImpl for JumpState {
const NAME: &'static str = "Jump"; const NAME: &'static str = "Jump";
fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> { fn check_interrupt(&self, state_context: &FighterStateContext) -> Option<FighterState> {
air_dodge::check_input(state_context) if state_context.input.has_command(FighterCommands::Jump) {
Some(FighterState::Jump(JumpState {
jump_type: JumpType::DoubleJump,
}))
} else {
air_dodge::check_input(state_context)
}
} }
fn update(&mut self, state_context: &mut FighterStateContext) { fn update(&mut self, state_context: &mut FighterStateContext) {
info!("TRF1 {}", state_context.translation.0);
air::integrate_gravity(state_context.velocity, state_context.fighter_attribs); air::integrate_gravity(state_context.velocity, state_context.fighter_attribs);
air::apply_air_drift(state_context.velocity, state_context.fighter_attribs, state_context.input); air::apply_air_drift(
state_context.velocity,
state_context.fighter_attribs,
state_context.input,
);
air::apply_air_motion( air::apply_air_motion(
state_context.velocity, state_context.velocity,
state_context.translation, state_context.translation,
state_context.prev_translation, state_context.prev_translation,
); );
info!("TRF12 {}", state_context.translation.0);
} }
fn on_enter(&mut self, state_context: &mut FighterStateContext) { fn on_enter(&mut self, state_context: &mut FighterStateContext) {
if let JumpType::DoubleJump = self.jump_type {
state_context.input.clear_command(FighterCommands::Jump);
}
let movement_stick_x = state_context.input.get_last_frame().movement.x; let movement_stick_x = state_context.input.get_last_frame().movement.x;
if movement_stick_x.is_zero() || movement_stick_x.signum() == state_context.facing_direction.to_sign() { match self.jump_type {
state_context.animation_transitions.play( JumpType::ShortHop | JumpType::LongJump => {
state_context.animation_player, if movement_stick_x.is_zero()
state_context.animations.clips[&AnimKind::JumpForward], || movement_stick_x.signum() == state_context.facing_direction.to_sign()
Duration::ZERO, {
); state_context.animation_transitions.play(
} else { state_context.animation_player,
state_context.animation_transitions.play( state_context.animations.clips[&AnimKind::JumpForward],
state_context.animation_player, Duration::ZERO,
state_context.animations.clips[&AnimKind::JumpBack], );
Duration::ZERO, } else {
); state_context.animation_transitions.play(
state_context.animation_player,
state_context.animations.clips[&AnimKind::JumpBack],
Duration::ZERO,
);
}
}
JumpType::DoubleJump => {
state_context.animation_transitions.play(
state_context.animation_player,
state_context.animations.clips[&AnimKind::DoubleJump],
Duration::ZERO,
);
}
} }
let vertical_vel = match self.jump_type { let vertical_vel = match self.jump_type {
JumpType::ShortHop => state_context.fighter_attribs.short_hop_vertical_velocity, JumpType::ShortHop => state_context.fighter_attribs.short_hop_vertical_velocity,
JumpType::LongJump => state_context.fighter_attribs.full_jump_vertical_velocity, JumpType::LongJump => state_context.fighter_attribs.full_jump_vertical_velocity,
JumpType::DoubleJump => todo!(), JumpType::DoubleJump => {
state_context.fighter_attribs.full_jump_vertical_velocity
* state_context.fighter_attribs.air_jump_multiplier
}
};
match self.jump_type {
JumpType::ShortHop | JumpType::LongJump => {
state_context.velocity.x +=
state_context.fighter_attribs.jump_horizontal_velocity * movement_stick_x;
}
JumpType::DoubleJump => {
state_context.velocity.x =
state_context.fighter_attribs.air_jump_horizontal_velocity * movement_stick_x;
}
}; };
state_context.velocity.y = vertical_vel; state_context.velocity.y = vertical_vel;
state_context.velocity.x += state_context.fighter_attribs.jump_horizontal_velocity * movement_stick_x; state_context.velocity.x +=
state_context.input.clear_buffer(); state_context.fighter_attribs.jump_horizontal_velocity * movement_stick_x;
} }
fn check_collision_interrupt( fn check_collision_interrupt(
@@ -153,7 +225,10 @@ impl FighterStateImpl for JumpState {
let grounded_common = GroundedStateCommon { let grounded_common = GroundedStateCommon {
current_line_id: res.line_id, current_line_id: res.line_id,
}; };
Some(FighterState::Land(LandingState { grounded_common, duration_counter: 0 })) Some(FighterState::Land(LandingState {
grounded_common,
duration_counter: 0,
}))
} else { } else {
None None
} }
@@ -169,3 +244,14 @@ pub fn check_input(
.has_command(FighterCommands::Jump) .has_command(FighterCommands::Jump)
.then(|| FighterState::JumpSquat(JumpSquatState::create(ground_common.clone()))) .then(|| FighterState::JumpSquat(JumpSquatState::create(ground_common.clone())))
} }
pub fn check_input_double_jump(
state_context: &FighterStateContext
) -> Option<FighterState> {
state_context
.input
.has_command(FighterCommands::Jump)
.then(|| FighterState::Jump(JumpState{
jump_type: JumpType::DoubleJump
}))
}
+3
View File
@@ -154,6 +154,9 @@ pub fn postprocess_input(
FighterCommands::SmashMoveLeft FighterCommands::SmashMoveLeft
}; };
if !input.has_command(command_to_set) {
dbg!(command_to_set);
}
input.set_lifetime(command_to_set, game_settings.input_common.input_buffer_size); input.set_lifetime(command_to_set, game_settings.input_common.input_buffer_size);
} }
} }
-1
View File
@@ -128,7 +128,6 @@ impl FGSegment2d {
if denom == FGWide::ZERO { if denom == FGWide::ZERO {
return None; // Parallel or collinear return None; // Parallel or collinear
} }
info!("{p0}, {p1}, {p2}, {p3}");
let s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / denom; let s = (-s1_y * (p0_x - p2_x) + s1_x * (p0_y - p2_y)) / denom;
let t = (s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / denom; let t = (s2_x * (p0_y - p2_y) - s2_y * (p0_x - p2_x)) / denom;
+1 -1
View File
@@ -6,7 +6,7 @@ use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Sub};
use super::int::{FGWide, FGi32}; use super::int::{FGWide, FGi32};
#[derive(Clone, Copy, PartialEq, Default, Debug, Reflect, Serialize, Deserialize)] #[derive(Clone, Copy, PartialEq, Default, Debug, Reflect, Serialize, Deserialize, Hash)]
#[reflect(opaque)] #[reflect(opaque)]
pub struct FGVec2 { pub struct FGVec2 {
pub x: FGi32, pub x: FGi32,