Hi everyone,
Can I have some help on that please?
I'm trying to make a custom timer but I'm having some strange issue:
When the timer starts the game freezes until it finish.
Character script example:
extends KinematicBody2D
var move_speed = 100
var direction = Vector2.ZERO
var melee = load("res://melee.gd").new()
var UP_DIR = Vector2(0, -1)
var DOWN_DIR = Vector2(0, 1)
var LEFT_DIR = Vector2(-1, 0)
var RIGHT_DIR = Vector2(1, 0)
func _physics_process(delta):
melee.process(delta)
if Input.is_action_pressed("move_up"):
direction += UP_DIR
if Input.is_action_pressed("move_down"):
direction += DOWN_DIR
if Input.is_action_pressed("move_left"):
direction += LEFT_DIR
if Input.is_action_pressed("move_right"):
direction += RIGHT_DIR
if Input.is_action_just_pressed("melee"):
melee.start_capability()
move_and_slide(direction * move_speed)
direction = Vector2.ZERO
Script with the cooldown code:
extends Node2D
var started : bool = false
var capability_duration : float = 50
var capability_performed : float = 0.0
func process(delta):
if (started == false):
return
while capability_performed <= capability_duration:
print(capability_performed)
capability_performed += delta
started = false
capability_performed = 0
func start_capability():
started = true
There is a project to replicate the issue in Github:
https://github.com/cassioKenji/godot-cooldown-issue
Thank you all!