having a problem with timer node. pls help

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

i was trying to make my player to dash in a short amount of time. But it dashed once and didnt dash again at all. And there was no issue with my scripting. And i think timer nodes might doesnt work well inside signals. or there is a problem with my scriipting?

And i was trying to troubleshoot, then what i found is that cool_down node doesnt start.

Here is my script:

dash_av = 1

if Input.is_action_just_pressed(“player_1dash”) and Input.is_action_pressed(“ui_right”):
dash()
if Input.is_action_just_pressed(“player_1dash”) and Input.is_action_pressed(“ui_left”):
dash()

func dash():
$dash_time.start()
maxspeed = 1500
motion.y += gravity * 2
acc = 2000
dash_av = 0

func _on_dash_time_timeout():
maxspeed = 500
acc = 100
$dash_cooldown.start()

func _on_dash_cooldown_timeout():
dash_av = 1

:bust_in_silhouette: Reply From: Skyfrit

Here is the code I test, it work.

var dash_av = 1

func _ready():
	$dash_time.one_shot = true
	$dash_cooldown.one_shot = true

func _input(event):
	if event is InputEventKey:
		if Input.is_action_pressed("ui_right") and dash_av == 1:
			dash()
		if Input.is_action_pressed("ui_left") and dash_av == 1:
			dash()

func dash():
	print("dash")
	dash_av = 0
	$dash_time.start()

func dash_time_timeout():
	print("dashtime_timeout")
	$dash_cooldown.start()

func dash_cooldown_timeout():
	print("dash_cooldown_timeout")
	dash_av = 1

TY so much, it worked

Tiez | 2020-12-07 12:21