Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Spafnar |
Hello, in my game I have two collectibles that spawn for the player to obtain. A coin, which is worth 10 score, and 1 cash, and a gem, which is worth 50 score and 10 cash. The coin spawns when the game begins, and whenever the player grabs it, it respawns immediately at a random location. The gem on the other hand is “rare” how I did this was set it up to a timer with a minimum of 5 seconds and a maximum of 30 seconds, and will spawn when timer timesout, also at a random location. However, what seems to be happening more often than I would like it to, is that the gem will spawn on top of the coin, or vice versa, and they trigger each other; My cash goes up by 11, and my score goes up by 60, and then they both disappear. (The coin respawns immediately after). They are both hooked up to this part of my script for random generation:
func _spawn_coin():
var coin_spawn_position = Vector2(randi()%500+31, randi()%550+31)
while coin_spawn_position == $Player.position:
_spawn_coin()
$CoinPosition.position = coin_spawn_position
$Coin._spawn($CoinPosition.position)
The gem spawn function is the exact same but replace the word coin with gem everywhere it is shown here. My question is, is it possible to prevent the two collectibles from spawning on top of one another? Or at least if they do, not to trigger each other? (There is an indent for func I had to make it look that way because it wasn’t showing up in the script text for my question.)