How do I make a random enemy spawn a key

0 favourites
  • 3 posts
From the Asset Store
Piano Tiles with Sound Keys - I don't have 50 words to type here
  • In my game i have 4 different enemies. When the player kills an enemy they spawn a key that opens a chest.

    I'd like to be able to have a different enemy spawn that key. EXAMPLE: player kills enemy 2, they spawn the key. If the player quits the game and restarts or passes that level on the next level(s) enemy 4 will spawn the key.

    Thanks for any help.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • In my game i have 4 different enemies. When the player kills an enemy they spawn a key that opens a chest.

    I'd like to be able to have a different enemy spawn that key. EXAMPLE: player kills enemy 2, they spawn the key. If the player quits the game and restarts or passes that level on the next level(s) enemy 4 will spawn the key.

    Thanks for any help.

    My first thought is to have an instance variable that is a boolean (hasKey - default to no). Then set an event to randomize it

    On Layout Start - > pick random instance --> set boolean to yes

    Or could do:

    On instance destroyed

    If instance count > 1

    If random(0,1) > 0.75 then spawn key

    Else (if instance count is 1) then spawn key

  • If you're wanting it to always be a different enemy then I would go the instance variable route like badmoodtaylor suggested. You're question sounds like you want this difference across multiple levels (layouts), so you would need to store the enemy number that had key last time in a global and filter him out next spawn.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)