![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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?
![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
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?
![]() |
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.
![]() |
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 = RandomNumberGenerator.new()
var doors_positions
var random_number
func randomize_door():
doors_positions = get_tree().get_nodes_in_group("doors")
rng.randomize()
random_number = rng.randi_range(1,doors_positions.size()-1)
spawn_enemy(doors_positions[random_number].position)