0
\$\begingroup\$
    if Input.is_action_just_pressed("forward") or Input.is_action_just_pressed("backward") or Input.is_action_just_pressed("left") or Input.is_action_just_pressed("right"):
      dash_count += 1
    if dash_count == 2 and dash_timer < double_press_time:
      horizontal_velocity = direction * dash_power * 2.5

This checks if the the movement inputs are being pressed, if yes... gain one 1 point in dash count... dash count returns to zero after 0.3 seconds

if dash count is 0, you can't dash... if dash count is 2, your character will dodge/dash in the direction of movement.

The system exists to allow dodging by simply double pressing the movement keys... but I also realized that is quite easy to dodge by mistake by simply switching directions....

How do I fix this without creating a different timer for every single input? Also I tried reducing the dodge timer, but after testing it with my brother, I realized around 0.25 and 0.3 seconds is the safest as even a child can manage to dodge correctly with this timer.

\$\endgroup\$
10
  • \$\begingroup\$ Maybe I read that wrong, but dash_count should only increase if you move in the same direction as the last input else reset the dash_count \$\endgroup\$
    – Zibelas
    Commented Jun 28, 2023 at 15:09
  • \$\begingroup\$ @Zibelas it uses an or || which in godot is literally or so for now it works by pressing any movement key combination really fast which at first i thought was super neat and very smarty from me because this way players could dodge diagonally in 360 directions... but after a few days (now) i noticed that it is very easy to dodge by mistake \$\endgroup\$
    – Cei
    Commented Jun 28, 2023 at 15:35
  • \$\begingroup\$ Why do you need a new timer for every single input? A single extra timer that keeps track when the last input was is enough. Either the last input is close enough or not. After every new input that timer gets updated \$\endgroup\$
    – Zibelas
    Commented Jun 28, 2023 at 17:34
  • 3
    \$\begingroup\$ If you go back to this answer: stackoverflow.com/a/75945029/402022 notice I kept track of the last direction (old_move_dir). I was using the dot product (move_dir.dot(old_move_dir) > 0.0) to allow the player to change direction while retaining the speed, but not do a half turn. I suggest you revisit that idea. You, of course, could me more restrictive than that if you need to. \$\endgroup\$
    – Theraot
    Commented Jun 28, 2023 at 20:31
  • 1
    \$\begingroup\$ Its not about the amount of button. Dodging is a core mechanic in Lost Ark and you still have 15 buttons for skills but if you miss a single dodge in a boss fight, that is usually your death. Fights are first about dodging and spamming as many skills as possible in a small window. It depends on your game, but if the player has to dodge so rarely that panic happens when a dodge is needed , it feels frustrating when the dodge goes in the wrong direction because of direction smashing. Double press to dodge is not wrong, but different direction keys for dodge will be hard to fine tune. \$\endgroup\$
    – Zibelas
    Commented Jun 29, 2023 at 6:40

1 Answer 1

1
\$\begingroup\$

As Theraot explaind in a comment, you only need one additional variable, to store the previously tapped direction. Only activate the dodge if the latest tap is in the same direction as the previous.

if Input.is_action_just_pressed("forward") or Input.is_action_just_pressed("backward") or Input.is_action_just_pressed("left") or Input.is_action_just_pressed("right"):
    if tap_count == 0 or dash_timer > double_press_time:
        tap_count = 1
    else if tap_count == 1 and direction.dot(previous_direction) > 0.0:
        tap_count = 2
        horizontal_velocity = direction * dash_power * 2.5

previous_direction = direction
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .