Make a pattern for an enemy.

0 favourites
  • 4 posts
From the Asset Store
Pixel Enemies for SHMUP consists of 45 enemy ship sprites to be used in your game.
  • Hi, I have a "small" problem.

    What I want to do is have an enemy with 2 attacks, 1 which is close range and a

    projectile attack. I want the enemy to be in Idle for 4 second, then use the projectile attack, the animation would repeat 3 times as he has to shoot for 3.6 sec, then he would be in idle for 1 sec, after he would walk toward the player for 5 sec then he would use the melee attack after that going back to idle to begin the loop again.

    I just can't script this. I tried with variables, with groups activating and deactivating each other, with more variables. NOTHING WORKS. Either the walk animation is stuck or he wouldn't stop shooting or he wouldn't play the melee attack etc.

    Also I would like to mention the enemy has 5 animations: Idle, Walk, Projectile attack, Melee attack and Death animation.

    Please help, I have been trying for the past few days nothing works.

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You need to give the enemy 'states' which can be an instance variable. Based on the states you can set the animations but it is the state variable that is most important.

    In a function :

    Set enemy.state=idle

    Wait 4 seconds

    Set enemy.state=shoot

    Wait 3.6 seconds

    Set enemy.state=idle

    Wait 1 seconds

    Set enemy.state=patrol

    ---

    Enemy on collision with player AND enemy.state=patrol

    Set enemy.state=melee

    ---

    On animation melee finished : run function

    --

    This becomes more than a small problem when you have more than one enemy in the level.

  • Thanks so much! I never used functions before, now I know just how powerful they are! THANKS MAN YOU ARE LEGEND!

  • One suggestion though, don't rely too much in fixed intervals. It's better to have an enemy fire when out of range, try to approach, check range again and fire if it's out of range or hit if it's on close combat range. Otherwise you risk havingan enemy attacking the air in close combat too far away from the player.

    On any attack animation ended {
     Player is on range {
     Attack in close combat;
     } Else {
     Fire a ranged attack;
     }
    }
    

    You can add a short idle time anywhere you see fit if you want it to pause sometimes.

    For instance:

    On any attack animation ended {
     Player is on range {
     Attack in close combat;
     } Else If random number < 0.3 {
     Wait 1 second;
     Fire a ranged attack;
     } Else {
     Fire a ranged attack;
     }
    }
    

    In this second example there's a probability the enemy will stop a while before firing.

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