fishfolk / punchy

A 2.5D side-scroller beatemup, made in Bevy

Home Page:https://fishfolk.github.io/punchy/player/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible to get stuck at bottom of map

odecay opened this issue · comments

It is possible to get stuck toward the bottom of the map such that it is only possible to move in X direction.
I vaguely remember it relating to the way the character is moved slightly downwards by the belly flop attack

2022-07-03.15-44-36.mp4

The belly flop doesn't play well with this. Not sure what's the best way to fix it. I think that the belly flop should not decrease the Y. I haven't played many beat-em ups, but the one I've played attacked only across the X axis.

Ok. This is another case of the 1-frame-lag (or something similar). The first frame of the animation runs sometimes for 7 (Bevy) frames, sometimes for 8. When it runs for 7 frames, it causes the computation to shift the sprite up less than it should.

This diff displays the problem (it has some simplifications):

diff --git i/src/main.rs w/src/main.rs
index 54838af..fffb59f 100644
--- i/src/main.rs
+++ w/src/main.rs
@@ -628,6 +628,7 @@ fn unpause(keyboard: Res<Input<KeyCode>>, mut commands: Commands) {
 }
 
 fn player_attack(
+    mut frames_count: Local<u32>,
     mut query: Query<(&mut State, &mut Transform, &Animation, &Facing), With<Player>>,
     keyboard: Res<Input<KeyCode>>,
     time: Res<Time>,
@@ -649,10 +650,24 @@ fn player_attack(
                 }
             }
 
+            if animation.current_frame == 0 {
+                *frames_count += 1;
+                println!("FC0:{}", *frames_count);
+            }
+
+            if animation.current_frame < 1 {
+                transform.translation.y += 100. * time.delta_seconds();
+            } else if animation.current_frame < 2 {
+                transform.translation.y -= 100. * time.delta_seconds();
+            }
+
             if animation.current_frame < 1 {
-                transform.translation.y += 180. * time.delta_seconds();
-            } else if animation.current_frame < 3 {
-                transform.translation.y -= 90. * time.delta_seconds();
+                println!(
+                    "AF:{} Y:{}, TD:{}",
+                    animation.current_frame,
+                    transform.translation.y,
+                    time.delta_seconds()
+                );
             }
         }
     }

you'll notice that sometimes, only 7 (or even 6) log units are printed.

Okay this is good info will be helpful in getting to the bottom of this.

Is this considered close, or you'd like an improved solution? I can work on it, in the latter case.

I think its closed, can reopen if it pops up again but I think your fix was good.