'Spawn enemies RANDOMLY' ????.....

0 favourites
  • 9 posts
From the Asset Store
Pixel Enemies for SHMUP consists of 45 enemy ship sprites to be used in your game.
  • Hi there!

    As you can see in this image, I need to spawn the enemy randomly in the ground while the Player is running.

    I've manage to draw all the animations, player and zombie, such as the Input Movement as well.

    All I need is various enemies to rip their head off!! :P

  • Depends how the game works, is it an infinite runner? Does the player remain at the same co-ordinates so you have faked the running or is it a platformer and he is just running to the right? You could wait a random amount of time so every random(x,y) seconds if the character is constantly running, or you can choose co-ordinates in a random range spawn at x=random(x,y) and y= always the same floor co-ordinate.

  • The Player can run, in the ground, left or right and the camera follows him.

    I didn't get it well, but I'll try it. Thanx!

  • you can also spawn the enemy from a an invisible sprite having line of sight to the player. when the player gets near and gets to the range of los of the invisible sprite, it spawns the zombies. but if its endless runner,lion's suggestion could be considered.

  • I was thinking more left & right to explore the scenery, but I'll give it a go to an endless runner. Otherwise this doubt will be endlessly too :P

    Thanx for the support!

  • u could do a variable and add px's or distance traveled to it, based on player movement, for example u would need 2 variables

    oldX and curentX

    the condition format must be like this to be able to check distance and rewrite

    everytick setoldx >player.x

    onleftpress orRightpress > setcurentX to player.x

    compare two variables > distance(oldx, 0 , curentx,0 ) is greater or equal 200 >action> create zombie at player.x +100px (or -100px depending where the player is facing.)

    not sure if u want it like this, but what this would do is check if the distance between last position of player and curent position is greater or equal to 200px then will spawn a enemy around player at 100 px, to check where the player is facing, you could make use of the left and right button when u move by adding a 3rd variable and call it "moveLR" value of 0 being left and 1 being right

    and when u press left u setup moveLR to 0 and when u move right u setup moveLR to 1

    then u just check if moveLR is 0 or 1 and spawn the zombie to player.x-100px if moveLR = 0 and player.x + 100px if moveLR=1

    i can do a quick example if u want.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • since we dont wanna put the spawning invisible sprite to an endless road(its tiring),we can try to find a way to put this spawner in specific distances using maths or some features in the game(i havent tried it).their gotta be a feature to do this. or we can use timer, i.e. after x seconds it spawns. but the latter is kinda inconvenient cause if player misses to kill the zombies in time, their would be too much zombies after x seconds.

    i didnt see george zaharia post while i was writing this.

    his post is the right answer.

  • since we dont wanna put the spawning invisible sprite to an endless road(its tiring),we can try to find a way to put this spawner in specific distances using maths or some features in the game(i havent tried it).their gotta be a feature to do this. or we can use timer, i.e. after x seconds it spawns. but the latter is kinda inconvenient cause if player misses to kill the zombies in time, their would be too much zombies after x seconds.

    i didnt see george zaharia post while i was writing this.

    his post is the right answer.

    you could do it with a timer also, just make sure u limit the zombies count max... to like 5 or so...

    like every 2 seconds

    zombies.count<4

    action>>>create a zombie at X random...

    this way u always have only 4 zombies on screen at all time. or newly spawned.

    anyway here is my example, i made 2 options inside, line 7 block works with the every1 second block on line 2 i think, and line 13 is just a variable controled by how long u keep pressing keys left and right aka moving character... i think line 13 is way better than my other version... is simpler... basically what line 13 does, is everytime u press left or right adds 1 to a variable when that variable hits 200 means u moved 200 "units" and spawns a zombie in ur face at 200 px ... then resets itself and u can move again spawning more zombies, u can alter it as u want... add a random position like random(200, 1500) depending on ur screen layout size etc... 200 being the minimum distance from player zombies will spawn... ud want them to be at somewhere 200px away so u have time to react.

    everything else is adjustable play around with it ... have fun, and hope it helped in any way.

  • Thank you so much!

    This is great stuff... I'll have to compile everything and see the best way to go, or try to do in this case...

    I'll post a video when I finally handle this!

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