Chasing enemies in top-down shooter

Get help using Construct 2

Post » Sat Feb 15, 2014 1:31 am

Hi,

After doing the platform and shooter tutorials, I've been trying to customise the shooter game with some additional features.

I've got almost everything working properly (if not elegantly): doors open when the player collides, apart from the red door which requires a key; the red key and medkit spawns at random positions, but not in walls, doors and the player; ghosts chase the player when shot and pass through walls.

But I wanted the ghosts to wander the layout, chase the player when they see him, and speed up when they're shot. The ghosts have LOS, but they don't react to the player when it passes within their line-of-sight. (LOS is set in events 1 and 11.)

Can anyone suggest where I'm going wrong? The CAPX file is downloadable below.

I have checked the forums and tutorials for advice on this, but the only guides I could find were for platform games, and didn't do what I intended.

BTW Events 2 and 4 were my attempts at making the keycard and medkit spawn in random spots, but not walls, doors or the player. I've disabled them for now, while I try and think of more elegant way of doing it that actually works.

My next jobs for this game are to add more layouts, a start screen, and sound.

Thanks.

- RIchard

https://dl.dropboxusercontent.com/u/5328690/Construct/ghost%20shooter%20v1.capx
B
7
S
1
Posts: 17
Reputation: 646

Post » Sat Feb 15, 2014 2:13 am

I haven't looked at your capx, but I can give one piece of advice on using line of sight: if possible, ditch it for your enemies and just put it on your player. Then test every 0.1 seconds (or every 4-6 ticks if doing framerate dependent) to see what enemies the player can see, and activate them(use an instance var). If the player can't see them (else), deactivate.

On the other hand, if you want them to flee from approaching bullets, then you will need LOS on each enemy...but if you just want them to REACT to the players attacks, you can use the bullet's vector of motion to figure where it came from, and tell the enemy to flee in the opposite direction.

This approach should let you get away with a lot more on-screen enemies (and/or a lot less cpu usage).
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,187

Post » Sat Feb 15, 2014 4:48 am

Hey Richard!

I dont have any experience using LOS, but comparing distance in a "For Each" loop instead seems to do what you are looking for.

Does this work for you?

dl.dropboxusercontent.com/s/pbcfbq8xttgicx5/ghost%20shooter%20v1test.capx
B
12
S
2
G
1
Posts: 26
Reputation: 835

Post » Sat Feb 15, 2014 1:12 pm

TiAm: Thanks for the advice. I'll look into moving the LOS command into the player. The behaviour I wanted to create was this:

1. On start monsters patrol the layout in a random pattern.
I did this by having the monsters face a random angle, and ricochet off layout edges in a different direction.

2. When shot, monsters chase player.
For this I set up an instance variable boolean on the monster which turns true when a bullet hits it. This causes the monster to change angle to face the player, and increase speed.

These are the behaviour rules I'm having problems with.

Bonesey: Thank you for your "for each" loop. It's very close to the behaviour I wanted to create, and it'll be very useful later. But I was trying to enable the player to approach monsters without being seen. The reason for these is I was aiming to make the monsters to move faster than the player when they spot him and are shot, to encourage "sneak-up-and-shoot-em-up" gameplay.

3. When player crosses a LOS arc in front of monster, monster "sees" player and chases him.
By "LOS" I mean an area in front of the monster: not necessarily the LOS function itself.

4. When player moves out of the LOS arc, monster stops chases returns to normal behaviour. (Allows player to evade.)

5. When player approaches monster from behind, monster ignores player.

- Richard
B
7
S
1
Posts: 17
Reputation: 646

Post » Tue Feb 18, 2014 7:50 pm

I've managed to (just about) work out how to get the ghosts doing what I want.

I'm sticking a pin in the game now, as I want to move onto other things (like figuring out how to use Construct properly), but I've put the game up on the Arcade because someone I know is interested in what Construct can do.

Thanks for the help.

http://www.scirra.com/arcade/shooter/12439/ghost-hunt
B
7
S
1
Posts: 17
Reputation: 646


Return to How do I....?

Who is online

Users browsing this forum: ksiads, marc254, marcinkowski, mtnboy22, Rable and 6 guests