AI Awareness

For questions about using Classic.

Post » Thu Jun 23, 2011 1:46 pm

So, I've been scanning the forum for answer (like a good little forum user) but I've come across a question that needs professional help. Lol.

So, I'll just post the .cap and let you examine it as I'm asking these questions.

http://dl.dropbox.com/u/33283294/zombie.cap

Basically, what I'm attempting to do is program the AI for a zombie game. They way I started was just using the Line of Sight behavior. It was awesome and worked perfectly. Until I turned my sprites solid. Then, that ruined it because as I learned, the LOS runs off hotspots. So, back to the forum. I learned you can shoot an object at the player if is within the LOS of enemy and if it hits him, viola!

However, this only works with one enemy onscreen. I want individual enemies to have to see the player before attacking. The way I have it (since I don't know what I'm doing) is every zombie will fire a detector at the player (which works) but as soon as one hits him, ALL the zombies go after him. I need a way to make the zombies INDIVIDUALLY aware of the player. (by means of a private variable)
B
1
G
2
Posts: 5
Reputation: 635

Post » Thu Jun 23, 2011 9:44 pm

I have had the same problem in my game, I haven't come up with the solution I'm going to try for real yet, but here is how I think I'll do it.

Create an object called "detector" and put it in the container of your zombie. This creates one for each zombie, and when you perform a "for each object" on the zombies, it will select the right contained detector.

Make sure the sprite is invisible, but has box collision detection and resize it to the shoulder-width of the zombie (or smaller for finer detection). Then set the centre of the detector to its parent zombie, and stretch it to the player.

If it doesn't overlap a wall while overlapping the player, it can see them. Might be handy to put a distance check in as well to ensure the player isn't miles away if you want.

Anyway, I hope it works =]
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Fri Jun 24, 2011 4:03 am

You just solved my problem. I had never heard of containers but it seems like a logical idea. Imma give it a shot in the morning and see what I can come up with.
B
1
G
2
Posts: 5
Reputation: 635


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests