patrolling and shooting enemy

0 favourites
  • 6 posts
From the Asset Store
Shoot balls to destroy as many blocks as possible, at each stage the game will become more difficult.
  • hello

    i created an enemy that is walking left and right and should fire a projectile if the player gets too close.

    the movement of the enemy is controlled by a boolean called "w_left", that toggles if the enemy collides with a sprite called "turn". as long as w_left is true the enemy walkes to the left and if it is false he walkes to the right.

    if the enemy is walking to the left (w_left is true) and the player is less than 200px away (enemy.x <= player.x + 200) it should fire a shot. i did the same accordingly for the other side.

    if the enemy is walking towards the player everything works smoothly, but if the enemy turns around and faces the other direction it is shooting constanly.

    i tried to cover all possible states that could occur but i was not able to figure it out. this drives me mad, i hope someone can help me.

    game

    file

    controls are:

    left - A

    right - D

    jump - L

    the black thing around the enemy should symbolise the range.

    thanks in advance

  • Event8

    add another condition

    Compare avgn.X => avgn.x <= e_zombie.x

    Event9

    add another condition

    Compare avgn.X => avgn.x >= e_zombie.x

    Seems that the logic works as intended from there.

  • thank you very much <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for this Pete! I tried three different methods for back-and-forth enemy movement. Your 'boolean' approached worked perfect!

  • File Not Found...

  • both files not found

    <img src="smileys/smiley19.gif" border="0" align="middle" />

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