Enemy detect player and shoot

0 favourites
  • 9 posts
From the Asset Store
Shoot balls to destroy as many blocks as possible, at each stage the game will become more difficult.
  • Sounds simple enough but I cannot quite pull it off. Currently all enemies begin to shoot and the bullets don't always head in the right direction.

    I've searched the forum and couldn't find anything. Even in the 'How Do I...' FAQ, the link to the topic on enemy shooting wasn't quite what I needed.

    Does anybody have a simple capx file with Enemy detects Player.X+200 + spawns object bullet in player direction etc etc. Something simple that I can copy and paste the events from please?

    Here is how the game currently looks. The enemy/bullets have no effect on the player yet as I wanted to fix the way the enemies behave before I start messing around with health and lives etc

    http://dl.dropbox.com/u/44025915/Game1/index.html

  • Have you try to use distance() ?

  • Can you be more specific please, I'm still new to all of this <img src="smileys/smiley9.gif" border="0" align="middle" />

    Where will I find 'distance()'?

  • Have you in mind something like this? dl.dropbox.com/u/5214903/GM/Shooting%20turrent.zip

    Or maybe this could also help to get an idea

    scirra.com/forum/topic45770_post286384.html

  • I could work with those but surely there is a simpler way?

    Without using overlapping objects as a firing zone etc?

    Can it not just be the case that if my player gets 'x' distance away from an enemy then the enemy will begin shooting in his direction?

    I would be extremely greatful is someone can just throw together a quick example of this if it is possible.

    But thanks so far for your help either way :)

  • Well, if it was construct classic I'd say 'use the Line of Sight behavior' but since it's not, I really cant figure out how to make things in construct 2

    I'm also having this kind of problem, specially cause I didnt get used to construct 2 interfaces and lack of behaviors / objects like particles =/...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Your game has enemies that shoot horizontally, And I can more or less feel that you only want the enemies to shot when you are at their level.

    The easiest way to achieve that is to put some invisible detection box that will do the work for you.

    And I think you can make the system work with :

    Every Tick 
          -> Enemy.active = false
    
    detectionBox is overlapping Player
    detectionBox is overlapping Enemy
    ---System : compare Abs(Player.X-Enemy.X)<200
          -> Enemy.active = true
    
    Is Enemy.active
    Every 1 seconds
    ---Player.X > Enemy.X
          -> Spawn Bullet
          -> Bullet set angle to 0
    ---Player.X < Enemy.X
          -> Spawn Bullet
          -> Bullet set angle to 180

    Enemy.active is a BOOLEAN instance variable.

    I set it to false every tick and then if the player and the enemy is over the same detection box, it is set to true (the event are read from top to bottom every tick before the system draw the result)

    After that, in sub event I check for horizontal distance by checking how many pixel they are appart (with the abs() I don't care if the player is on the left or right of the enemy)

    And then if the Enemy.active is set to true I make it spawn bullet at the correct angle (in your game it seems that you always fire horizontally so 0? or 180?)

    And that's it

  • I've set it all up as above. I feel i's nearly there now, but when it shoots it shoots in both directions! Here's how it looks. Are there any obvious things I have done wrong?

    <img src="http://dl.dropbox.com/u/44025915/Enemy%20Shoot.png" border="0" />

    If someone could just put together a simple capx file with these events actually working then it would be much easier. It could also be used for people in the future with the same problem.

    I appreciate all the help so far though. Many thanks.

  • well... your event sheet is a mess

    bring the capix I'll show you

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