Enemy detect player and shoot

Get help using Construct 2

Post » Fri Nov 04, 2011 10:26 pm

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
ImageImage
Mr. Green - Platform/puzzle game out now!
B
24
S
7
G
1
Posts: 222
Reputation: 3,325

Post » Fri Nov 04, 2011 10:39 pm

Have you try to use distance() ?
B
23
S
5
G
5
Posts: 112
Reputation: 4,737

Post » Fri Nov 04, 2011 10:44 pm

Can you be more specific please, I'm still new to all of this

Where will I find 'distance()'? FredQ2011-11-04 22:44:27
ImageImage
Mr. Green - Platform/puzzle game out now!
B
24
S
7
G
1
Posts: 222
Reputation: 3,325

Post » Fri Nov 04, 2011 11:23 pm

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

Or maybe this could also help to get an idea
http://www.scirra.com/forum/topic45770_post286384.html#286384
B
43
S
9
G
5
Posts: 231
Reputation: 7,291

Post » Fri Nov 04, 2011 11:52 pm

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 :)FredQ2011-11-04 23:58:52
ImageImage
Mr. Green - Platform/puzzle game out now!
B
24
S
7
G
1
Posts: 222
Reputation: 3,325

Post » Sat Nov 05, 2011 3:57 am

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 =/...
B
11
S
2
G
2
Posts: 7
Reputation: 1,511

Post » Sat Nov 05, 2011 5:08 am

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 :

[code]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[/code]

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 itYann2011-11-05 05:10:37
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Nov 05, 2011 1:40 pm

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?



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.
ImageImage
Mr. Green - Platform/puzzle game out now!
B
24
S
7
G
1
Posts: 222
Reputation: 3,325

Post » Sat Nov 05, 2011 2:18 pm

well... your event sheet is a mess

bring the capix I'll show youYann2011-11-05 14:19:21
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346


Return to How do I....?

Who is online

Users browsing this forum: CavalierBubble, Evanetot and 17 guests