How do I spawn a single bullet when player in line of sight

  • Hi folks

    I have the 'baddie' at the top of the screen moving left and right.

    When the baddie has line of sight to the player, spawn a bullet.

    This works great, however, the baddie is spawning bullets as fast as it can, creating a solid line of bullets.

    What I'd like is for it to just spawn say 1 bullet per second or so, hence I put a system->wait in.

    The bullet spawn is setup as in the attached image.

    The 0.2 second wait was me just trying different wait times. I had it up to 5 seconds but it didn't affect the bullet spawn speed.

    I've tried changing the bullets speed and gravity but that hasn't helped.

    The full capx is here: https://dl.dropboxusercontent.com/u/14979031/bullet_fail.capx

    Any help appreciated.

    And thanks to Velojet for the great tutorial that started this off https://www.scirra.com/tutorials/243/building-a-platform-game-a-beginners-guide

  • Try this and work it out from this tutorial

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Lordshiva1948 Many thanks for the demonstration. I can see from your example how to get the 'baddie' to fire when the player collides with other objects, very cool

    I do notice that your example does not have any logic to control the number of objects spawned, so I can still get a nearly solid line of bullets going down the screen by going over the same bullet spawn point. I guess in this case I could add a boolean instance var to each spawn point, and as the player goes over the spawn point toggle the boolean, so multiple collisions with the same spawn point would not trigger multiple bullets.

    However, in the logic I'm trying to run, the baddie should only fire when the baddie has line of sight to the player.

    So if there are, for example, 2 seconds where the baddie can see the player, it 'should' fire once per second (for example), but in my case it fires as fast as it can for the 2 seconds that the player is in line of sight.

    So, although your example has given me food for thought, and some great ideas, unless I'm missing something I'm still stuck with my original problem.

    Thanks for your help

    Nick .

  • Nick you are on right path think. First break everything down in small chunk. Design 1 thing at time try out your enemy shooting bullets and then work your self up ward

  • quick example of one method

  • RamPackWobble

    Excellent! That works spot on, many thanks for the demo.

    I've not user the Timer before, so I'll have some fun messing with that.

    Thanks again

    Nick .

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