Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ROBOTOO007 |
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):
move_and_collide(CalculateVelocity())
cur_state = states[0]
if Input.is_action_just_pressed("ui_select"):
jump()
if Input.is_action_just_pressed("click"):
dash(get_viewport().get_mouse_position())
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
else:
velocity.y += gravity * get_physics_process_delta_time()
return velocity
however this makes the game crash :(,
ANY HELP IS APPRECATED
thanks for taking a look