Using await/async instead of Timer Node
Asked Answered
R

1

0

Hi im'a newbie,
I'm developing a top-down shooter game in Godot, and I currently have a working function within my Player class that enables shooting every 0.5 seconds. While the current implementation functions well, I'm curious about the potential disadvantages of using async and await. Is there a better way to achieve this without resorting to the use of a timer node?

private async void Shoot(){
canShoot = false;
Area2D bulletInstance = (Area2D)bullet.Instantiate();
AddChild(bulletInstance);
bulletInstance.GlobalPosition = GetNode<Marker2D>("./Muzzle").GlobalPosition;
await ToSignal(GetTree().CreateTimer(.35), "timeout");
canShoot = true;
}

Rogatory answered 9/12, 2023 at 9:7 Comment(0)
C
1

Rogatory Yes. Use a timeout signal handler instead of await. If you are a newbie, stay clear of awaits for the time being.

Cleveland answered 9/12, 2023 at 9:21 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.