Jump Left and Jump Up lag
Description
Hi! I noticed that, when the character jumps to Left or Up direction, the game lags if the player holds a key direction at the same moment. The problem is related to the fact that the function "update_jump" relies on a mathematical formula that might create some inconsistencies: @real_x = ((@real_x * @jump_count + @x * 128) / (@jump_count + 1)).round >> 2 << 2 @real_y = ((@real_y * @jump_count + @y * 128) / (@jump_count + 1)).round >> 2 << 2
In fact, dividing and rounding (also with >> and <<) might create assimmetry when the direction is negative (up and left) when compared to positive (right and down). If I print the difference between each iteration of @jump_count, we have the results I wrote at the bottom of the post.
As you might observe, the list of zeros that we find at the end of left movement are interpreted by "moving?" as NOT moving anymore, and therefore the game is able to take as an input a new direction while we are still at mid-air, causing the lag. An opportune solution is to think about a new formula that doesn't converge to zero too fast. OR we can opt for the following:
def moving? return (@real_x != @x * 128 || @real_y != @y * 128) || jumping? end
Good luck! I hope it helps :)
when we go left:
-16, 0
-16, 0
-16, 0
-12, 0
-12, 0
-12, 0
-12, 0
-12, 0
-12, 0
-12, 0
-12, 0
-12, 0
-8, 0
-8, 0
-8, 0
-8, 0
-8, 0
-8, 0
-8, 0
-8, 0
-4, 0
-4, 0
-4, 0
-4, 0
-4, 0
-4, 0
-4, 0
-4, 0
-4, 0
0, 0
0, 0
0, 0
0, 0
0, 0
0, 0
0, 0
when we go right:
12, 0
12, 0
12, 0
12, 0
12, 0
12, 0
12, 0
8, 0
8, 0
8, 0
8, 0
8, 0
8, 0
8, 0
8, 0
8, 0
8, 0
8, 0
8, 0
8, 0
8, 0
8, 0
4, 0
4, 0
4, 0
4, 0
4, 0
4, 0
4, 0
4, 0
4, 0
4, 0
4, 0
4, 0
0, 0
4, 0