From cbf074c021e1de4ee88505ee758b85ccaf2e8a55 Mon Sep 17 00:00:00 2001 From: hgn Date: Tue, 28 Nov 2023 04:24:26 +0000 Subject: [PATCH] an arbitrary way to fix grind velocity leaks --- player_skate.c | 22 +++++++++++++++++++++- player_skate.h | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/player_skate.c b/player_skate.c index 44845ac..215c1c7 100644 --- a/player_skate.c +++ b/player_skate.c @@ -1540,7 +1540,6 @@ static void skate_grind_decay( struct grind_info *inf, float strength ){ static void skate_grind_truck_apply( float sign, struct grind_info *inf, float strength ){ struct player_skate_state *state = &player_skate.state; - /* REFACTOR */ v3f ra = { 0.0f, -k_board_radius, sign * k_board_length }; v3f raw, wsp; @@ -2570,6 +2569,27 @@ begin_collision:; } else if( stick_frames == 0 ){ /* TODO: EXIT SOUNDS */ } + + if( (state->activity_prev < k_skate_activity_grind_any) && + (state->activity >= k_skate_activity_grind_any) ){ + state->velocity_limit = v3_length( localplayer.rb.v ); + state->grind_y_start = localplayer.rb.co[1]; + } + + if( state->activity >= k_skate_activity_grind_any ){ + f32 dy = localplayer.rb.co[1] - state->grind_y_start; + if( dy < 0.0f ){ + state->velocity_limit += -dy*0.2f; + } + state->grind_y_start = localplayer.rb.co[1]; + + + f32 speed_end = v3_length( localplayer.rb.v ); + if( speed_end > state->velocity_limit ){ + v3_muls( localplayer.rb.v, state->velocity_limit/speed_end, + localplayer.rb.v ); + } + } } static void player__skate_im_gui(void){ diff --git a/player_skate.h b/player_skate.h index c6a7860..735ffa6 100644 --- a/player_skate.h +++ b/player_skate.h @@ -76,6 +76,8 @@ struct player_skate{ float land_dist; v3f land_normal; v4f smoothed_rotation; + + f32 velocity_limit, grind_y_start; } state; -- 2.25.1