an arbitrary way to fix grind velocity leaks
authorhgn <hgodden00@gmail.com>
Tue, 28 Nov 2023 04:24:26 +0000 (04:24 +0000)
committerhgn <hgodden00@gmail.com>
Tue, 28 Nov 2023 04:24:26 +0000 (04:24 +0000)
player_skate.c
player_skate.h

index 44845acfe9bb7e831c97f28f8e833b0bfb5cc3d6..215c1c7f678091d8f97184aa98ddbf10ccd424c0 100644 (file)
@@ -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){
index c6a7860833077d8845bed38b8c22063f688a0ddf..735ffa613e8b59651fa73f4b6c544aae07c2c020 100644 (file)
@@ -76,6 +76,8 @@ struct player_skate{
       float land_dist;
       v3f land_normal;
       v4f smoothed_rotation;
+
+      f32 velocity_limit, grind_y_start;
    }
    state;