The Daily Click ::. Forums ::. Klik Coding Help ::. Stealth Game Enemy AI
 

Post Reply  Post Oekaki 
 

Posted By Message

Logiq



Registered
  09/04/2007
Points
  120
25th June, 2008 at 00:40:32 -

I need help with my Platform Game Enemy Artificial Intelligence.

So far I have 5 Active Objects to be used for the enemy's Line of sight. Each active object is longer and depending on how long it is the player will get around activating it. But once it is activated the enemy will chase the player and if the enemy is close enough they will attack the player. If the player gets out of it's line of sight for too long then the enemy will enter the lost state and finally return to his patrol location and also going into the patrol state.

Patrol
Pursue
Attack
Lost

Every time I have looked something up to solve this problem I see a post to just ask somebody to do it for you. I would rather not have somebody do it for me but if that's the only way I would gladly appreciate it.

Here is a link to the game if you need something to reference what I am talking about.
http://www.megaupload.com/?d=WSEM7SEP

 
Hello guys! I'm New! -- I've been new for a year now...haha

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
25th June, 2008 at 06:27:39 -

http://create-games.com/article.asp?id=1620

Dines wrote that article a while ago.

It should give you some ideas.

 
My signature is never too big!!!

Assault Andy

Administrator
I make other people create vaporware

Registered
  29/07/2002
Points
  5686

Game of the Week WinnerVIP Member360 OwnerGOTM JUNE - 2009 - WINNER!GOTM FEB - 2010 - WINNER!	I donated an open source project
25th June, 2008 at 06:56:03 -

I don't think you really need that many actives. I would probably use one or two. To detect how far away the enemy is from the player you should simply use a distance formula and then have one active for the line of sight. So if the play is in the line of sight of the enemy, and the distance between them is less than say 100 pixels, then you should make the enemey attack.

As for the states, you just kind of make them up! Think about how you think they should act. What I would do is have an alterable value that represents each of the states of the enemy. Eg, Alt a = 1, then he's patrolling, if it equals 2 then he's persuing, etc.

I would also have another alterable value as a timer. So say the enemy is pursuing you, "alt a = 2" but then you're no longer in his line of sight, then you should start subtracting from that timer (which you set to a value at the start). Then when the timer = 0 and the player is not in the enemy's line of sight you can change the status of the enemy to Lost.

That's just a rough example of the way I would do it.

 
Creator of Faerie Solitaire:
http://www.create-games.com/download.asp?id=7792
Also creator of ZDay20 and Dungeon Dash.
http://www.Jigxor.com
http://twitter.com/JigxorAndy

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
25th June, 2008 at 07:01:41 -

Ok. This may not be too easy to understand - ask if you want clarification on anything. Hope it helps.


Firstly, you're going to need to allocate one of the enemy object's alterable values to store its current state.

ie.
if Enemy(alterable value S) = 0 then enemy is patrolling
= 1 then enemy is pursuing/attacking
= 2 then enemy is lost


Patrol -> Pursue
You need to make sure that any events which are only relevant when in the patrol state, start with "if alterable value S = 0". Otherwise all the enemies will do the same thing.

Firstly, you need all the normal events that deal with enemy movement whilst patrolling (move, bounce etc).

Also, this is where you detect the player.
I see you're using invisible detector objects, which is perfectly fine for this kind of a game.


Assuming you have multiple enemies, you need to match the detectors to their enemy.

+start of frame
>>> spread value 0 in detector value S
>>> spread value 0 in enemy value S


So, you need an event along the lines of;

+ alterable value S = 0
+ player is overlapping detector
>>> set enemy alterable value S to alterable value S of detector
(so the correct enemy enters pursue state - that was the point of the previous event).




Pusuing/Attacking -> Lost
Again, any events which only apply when in pursuing/attacking state, must start with "if alterable value S = 1".

The kind of events you need are;

* if alterable value S = 1 >>> look in direction of player (or more complex pathfinding would be good)

* if alterable value S = 1 >>> set enemy alterable value D to distance from player

* if alterable value S = 1
+ if alterable value D < attack range
>>> shoot bullet in direction of player


* if alterable value S = 1
+ if alterable value D > max vision range
>>> set enemy alterable value S to 2 (so enemies enter lost state if player is far away - you could use your detectors instead of comparing distance).





Lost -> Patrol
Again, any events which only apply when in lost state, must start with "if alterable value S = 2".

I don't know - either wander around for a bit, or maybe return to start location (have an invisible marker object for each enemy to aim at when in lost state).

Also,

if alterable value S = 2
+ every 1 second
>>> add 1 to alterable value T

if alterable value S = 2
+ if alterable value T = 10
>>> set alterable value S to 0
>>> set alterable value T to 0

(this makes the enemy return to patrolling after 10 seconds - alternatively, run the event if enemy overlaps start point marker).


You also need the same detection events as in patrol state, incase the player becomes visible gain while the enemy is in lost state.

 
n/a

Logiq



Registered
  09/04/2007
Points
  120
25th June, 2008 at 12:00:36 -

Originally Posted by Sketchy




Assuming you have multiple enemies, you need to match the detectors to their enemy.

+start of frame
>>> spread value 0 in detector value S
>>> spread value 0 in enemy value S


So, you need an event along the lines of;

+ alterable value S = 0
+ player is overlapping detector
>>> set enemy alterable value S to alterable value S of detector
(so the correct enemy enters pursue state - that was the point of the previous event).



So I am going to assume that you left some events out like set the position of the detector to the enemy, correct?

For the event above should the first condition be either for the enemy or the detector:


+ alterable value S of Enemy or Detector = 0

I wanted to clarify that if I spread the AI STATE value (value S) on the detectors then wouldn't those numbers raise with each instance I have of them. Then when the play overlaps them the enemy's value will be set to speaded value and not the value of the next state "pursue"




 
Hello guys! I'm New! -- I've been new for a year now...haha

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
25th June, 2008 at 16:47:39 -

you are correct, I did skip lots of events, but they'll depend on how your engine works - you seem to have that part figured out already from what i saw.

you're also right that i messed up.
sorry, i confused myself there

this should work...

+start of frame
>>> spread value 1 in detector value B
>>> spread value 1 in enemy value B
(these are basically unique id #s for each object)

+always
>>> set detector value S to enemy value S
(you don't need to specify which detector and which enemy)

+ detector value S = 0
+ detector is overlapping player
>>> set global value A to detector value B

+ enemy value B = global value A
>>> set enemy value S to 1
>>> set global value A to 0

Image Edited by the Author.

 
n/a

Logiq



Registered
  09/04/2007
Points
  120
30th June, 2008 at 12:58:22 -



+start of frame
>>> spread value 1 in detector value B
>>> spread value 1 in enemy value B
(these are basically unique id #s for each object)

+always
>>> set detector value S to enemy value S
(you don't need to specify which detector and which enemy)

+ detector value S = 0
+ detector is overlapping player
>>> set global value A to detector value B

+ enemy value B = global value A
>>> set enemy value S to 1
>>> set global value A to 0



So after looking over it during the weekend I think I understand it now.

Value S = AI STATE
Value B = ID
Global A = Place holder

Is that correct? From what you described in your fixed version I was able to make each enemy go into the AI state of "1" individually.



if alterable value S = 1 >>> look in direction of player (or more complex pathfinding would be good)



could you give me an idea or examples of a more complex Pathfinding for a platform game. The one idea I had did not seem to work at all.

 
Hello guys! I'm New! -- I've been new for a year now...haha

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1971

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
30th June, 2008 at 19:03:09 -

I'm glad it worked in the end.

I am by no means an expert on platform games - I've never even *tried* to make one.

Just moving left/right towards the player is ok, but a bit boring. It can be combined with more "intelligent" behaviours though.

If you want enemies to be able to get over objects, jump from one platform to another, climb ladders etc to get to the player, the easiest way is probably to design your levels with lots of strategically placed invisible "helper" objects. These have effects like telling the enemy to jump or crawl or climb or change direction etc when hit from a particular direction or when the player is in a particular area. It's very crude, but it's easy and might well prove sufficient.

Aside from that, I don't know - search here and at the clickteam forums...

good luck

 
n/a
   

Post Reply



 



Advertisement

Worth A Click