0 votes

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)
Godot version 3.4.3
in Engine by (14 points)

1 Answer

+1 vote

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.

by (498 points)

thanks, I'll try it

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.