playMaker

Author Topic: Spawn random game objects with no repeat in random order  (Read 879 times)

Aaddiction

  • Full Member
  • ***
  • Posts: 166
Spawn random game objects with no repeat in random order
« on: June 10, 2020, 04:05:44 AM »
I have a grid with spawn points from 1 to 9.

I have a player car and AI cars. I'd like to spawn the player car and the AI cars on those spawn points in random order without repeating or overlapping. Any ideas how to approach that?

Thank you!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Spawn random game objects with no repeat in random order
« Reply #1 on: June 10, 2020, 06:26:03 AM »
Hi.
Have your AI cars in an array and spawn points as well.

1st Do a Random Array on the 'Spawn Point' Array and store the index and the spawn point for your player (if it needs to be random)
and place your player there.
Then do 'Array Delete At' and use the index there.

Then use Array Get Next on the Spawn Point or Cars Array (depending if you have more spawn points than cars to place or vice versa. If both are more look to the other option below)

Store the car or spawn point and the index.
Then do a Random Array to get a random car or Spawn Point.
Then do 'Array Delete At' on the Array That you are doing the Random Array. (not on the Get Next one!)

Then Transition Back to the state with the 'Array Get Next'

Now IF you have more Spawn points AND more cars than you want to spawn..
Then use a Iterate (Ecosytem) instead of 'Array Get Next'
and do random on both Random Array's and also delete At For both.

On the iterate set the times you want it to loop for how many cars you want it to spawn.