Godot Version
4.3
Question
I have Shooter nodes that shoot projectiles once every TimeBetweenShots
seconds, and this works fine when the timer is by itself, even with the small amount of Timer weirdness that exists within every game engine.
What doesn’t work is that the shooters fall out of sync, fast. I’ve set up four shooters to shoot, with their times set in the editor to 1, 1.2, 1.4 and 1.6 seconds respectively, from left to right. The first time they all shoot, everything works fine. The second time onwards, they’re out of sync.
Here is the necessary shooter logic:
public override void _Ready()
{
ShootTimer = GetChild<Timer>(0);
ShootTimer.WaitTime = TimeBetweenShots;
ShootTimer.Timeout += Shoot;
ShootTimer.Start();
.
.
.
}
...
public void Shoot()
{
var projectile = Projectiles[currentProjectile];
if (!projectile.IsInsideTree())
{
AddSibling(projectile);
projectile.Activate();
}
else
{
projectile.Deactivate();
AddSibling(projectile);
projectile.Activate();
}
if (currentProjectile < Projectiles.Length - 1)
{
currentProjectile += 1;
}
else
{
currentProjectile = 0;
}
}
The ShootTimer isn’t One Shot, and setting the Process Callback to Idle or Physics doesn’t make much difference.
Do I make my own version of a Timer? Use one timer to control multiple Shooters? (Would require overhauling how Shooters are done), or do I just ignore it and move on with the game? It’s quite late into development and a lot of things are set in stone, and I don’t want to overhaul the game a third time.
Note: When talking about Shooters syncing up, I’m referring to maybe four who need to be synced, not every shot in every level needs to be synced up.