Timers not synchronized

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.

It sounds like they have different times to shoot, so of course they will end up out of sync. Could you explain further what you intended to happen?

Make only one Timer for Shoot. Every script take some time. I don’t think timers will block process frame to finish all stack of timers.

I am assuming when you mean out of sync is that you want the timing between each bullet to stay the same. If that is the case, your issue is that the timers restart immediately.

Here is an illustration:

The top is what you are doing, but the bottom is what you want.

The easiest way to fix this is to restart all 4 timers only when the last(1.6) timer finishes.

1 Like