Spawn Random Actor

RyanZGrieco

  • Posts: 14
Hello,

I am working on a side scrolling game, and have several "enemy" Actors that i would like to spawn at random. They will all spawn at the same interval, however i would like the actor that appears to be a different one each time.

Any help on how to make this occur would be appreciated. Thank you!

WitlessWonderer

  • Posts: 35
You could create an attribute that keeps track of the previous actor type created.  Then, in the code to create the next enemy actor, just check the attribute to see if it is the one that was created previously.

I am assuming that you are using a randomly generated number which corresponds to an actor type to select which actor type to spawn.  If this is the case, your game attribute could just be the randomly generated number of the previous enemy that was spawned.  Check with a conditional if the old number and the newly randomly generated number are the same.  If they aren't: use the new number to spawn a new enemy, if they are: regenerate a new random number.

How many different enemy types do you have?

RyanZGrieco

  • Posts: 14
i currently just have one actor spawning repeatedly. would ideally like to have random of 3-4 different actors. 

Bombini

  • *
  • Posts: 1385
Hi,
i use actors which i place in levels which spawn random enemies like below.
You can add a lot parameters like "if in level 3" and so on.
Ignore the send layer. THe kill command kills the blue actor (because you dont need it once enemy is created).

Take a look.
Cheers!






RyanZGrieco

  • Posts: 14
thank you. I will give that a shot!

gplar

  • Posts: 1118
Or, if you treat all enemies the same, you could have one enemy actor with several animations and let the actor itself set a random animation on creation.   ;)

kevinkerik

  • Posts: 1
If you don't mind, I will piggy back on this question with one similar of my own. I can use the above suggestion to randomize my actors in a game, but how would I go about saving the randomized scenario so that "player 2" will end up playing the exact same scenario as player 1. So it randomizes the game settings, then both players play the game and compare how they did given the same settings. and I am talking about independent playing not player 2 playing after player 1 is done. (they each play at a separate computer and not at the same time)

WitlessWonderer

  • Posts: 35
Let's assume there are 5 possible random actors and three spots for an enemy to generate.

Since that would be a multiplayer game, I would probably have the server generate a list of 3 numerical entries each being a number from 0 to 4.  Then the server could send this list to each client, which would use the list to generate the scene.

tigerteeth

  • Posts: 733
If you don't mind, I will piggy back on this question with one similar of my own. I can use the above suggestion to randomize my actors in a game, but how would I go about saving the randomized scenario so that "player 2" will end up playing the exact same scenario as player 1. So it randomizes the game settings, then both players play the game and compare how they did given the same settings. and I am talking about independent playing not player 2 playing after player 1 is done. (they each play at a separate computer and not at the same time)

Your problem is going to be setting up a server for online multiplayer.