problem implementing dashing in platformer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By avlakos

the issue is, that after pressing dash keybutton my player character starts to dash and never returns to the initial velocity. i can’t understand why it’s happening.
thanks for your help in advance

fragment of code:

func apply_movement():

  x_input = Input.get_action_strength("right") - Input.get_action_strength("left")
  velocity.x = lerp(speed * x_input, velocity.x, 0.2)

  if Input.is_action_just_pressed("dash"):
  velocity = move_and_slide(velocity, Vector2.UP)

func dash():

  velocity.x = lerp(dash_speed * x_input, velocity.x, 0.1)

func _on_DashTimer_timeout():

  velocity.x = lerp(speed * x_input, velocity.x, 0.2)
:bust_in_silhouette: Reply From: SnapCracklins

You may need to implement some sort of state or flag to distinguish between the two movement patterns. Something like:

var isDashing = false

And then just turn it on and off depending on what function runs.

thanks, I’ll try it

avlakos | 2022-04-11 18:06