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

Just started using Construct 2? Post your questions here

Post » Fri Apr 18, 2014 11:50 am

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
You do not have the required permissions to view the files attached to this post.
B
10
S
2
G
1
Posts: 42
Reputation: 798

Post » Fri Apr 18, 2014 12:41 pm

Try this and work it out from this tutorial
You do not have the required permissions to view the files attached to this post.
B
250
S
39
G
15
Posts: 1,953
Reputation: 40,623

Post » Fri Apr 18, 2014 7:53 pm

@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 .
B
10
S
2
G
1
Posts: 42
Reputation: 798

Post » Fri Apr 18, 2014 7:59 pm

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
B
250
S
39
G
15
Posts: 1,953
Reputation: 40,623

Post » Sat Apr 19, 2014 8:16 am

quick example of one method
You do not have the required permissions to view the files attached to this post.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Post » Sat Apr 19, 2014 8:37 am

@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 .
B
10
S
2
G
1
Posts: 42
Reputation: 798


Return to Beginner's Questions

Who is online

Users browsing this forum: Lordshiva1948 and 1 guest