0 votes

I'm using a single timer that can spawn mobs & coins on a random location around my player.

How do I change the timer's wait time 0.5s for mobs and then 5s for coins?

export (PackedScene) var mobscene
export (PackedScene) var coin

func _ready():

func onSpawnTimer_timeout():

var rng = RandomNumberGenerator.new()

$Player/MobPath/MobSpawnLocation.offset = rng.randi_range(0, 6000)
var mob = mob_scene.instance()
var coin = coin_scene.instance()

mob.global_position = $Player/MobPath/MobSpawnLocation.global_position

coin.global_position = $Player/MobPath/MobSpawnLocation.global_position
Godot version 3.5
in Engine by (27 points)

1 Answer

+2 votes
Best answer

I'm not sure it makes sense to use a single timer to handle multiple events that should happen at different intervals. While you can certainly change a timer's wait time (by setting it's wait_time property), it'll be more complex than necessary.

Based on your suggested time values, you could run a timer at a 0.5 second interval to spawn mobs and then spawn coins every 10th time the timeout even fires, but that's pretty brittle and also unnecessarily complex.

I'd suggest that you use 2 timers - one for the mobs and one for the coins. That's clean and simple.

by (19,292 points)
selected by

Okie dokie

Thank you so much <3

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.