How can I spawn an enemy I different door position?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bluefrag

How to spawn my enemy at a doors position using position 2D but I want to
The enemy spawn at different doors
How can I randomize it?

:bust_in_silhouette: Reply From: Vininski

I would add the potential spawn positions to an array and generate a random number from 0 to the array size and use that to access a random position in the array.

:bust_in_silhouette: Reply From: rhennig

There are several ways to do that but if you need a more specific answer you need to give more details about what you want to achieve…

But you can put all your position2D in a group called doors, then do something like:

var rng =
var doors_positions
var random_number

func randomize_door():
	doors_positions = get_tree().get_nodes_in_group("doors")
	random_number = rng.randi_range(1,doors_positions.size()-1)