0 votes

basically im trying to make a simple phone game that makes the character dash to the place where the player clicked on the screen.
the way i have this set up is i have a dash function:

func dash(pos):
    cur_state = states[2]
    dash_pos = pos
    dash_dir = (pos - position).normalized()

and here's my physics process function + the calculate velocity function i have:

func _physics_process(delta):
  cur_state = states[0]
  if Input.is_action_just_pressed("ui_select"):
  if Input.is_action_just_pressed("click"):

func CalculateVelocity():
    if cur_state == states[1]: #if state is jumping
        velocity.y = 0 - jump_power * get_physics_process_delta_time()
    elif cur_state == states[2]: #if state is dashing
        while position != dash_pos:
            velocity = dash_dir
        velocity.y += gravity * get_physics_process_delta_time()
    return velocity

however this makes the game crash :(,
thanks for taking a look

Godot version latest
in Engine by (120 points)

1 Answer

0 votes
Best answer

with your current code, the game is stuck in the while loop
change while to if.
but even like this, i think your character will keep moving left and right relatively the dash pos, since it's very unlikely that position+dash_dir==dash_posexactly.

maybe change the second if to

elif cur_state == states[2] and (position-dash_position).length()>0.1:
by (1,500 points)
selected by

thanks for the answer i fixed everything up nicely but the dash won't stop tho
still thanks a lot for your help :)

i fixed everything thanks

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.