The Daily Click ::. Forums ::. Klik Coding Help ::. A.I problem, all enemies starts to follow when only one gets alerted
 

Post Reply  Post Oekaki 
 

Posted By Message

Zip2kx



Registered
  17/05/2003
Points
  32
26th March, 2010 at 18:37:09 -

hi guys, been a while since i played with the click products so i have a simple question.
I have the enemies shoot a sight object every half second. When this object hits the player it sets the enemies alt.A value to 1.

and when value A is 1 the enemy looks at the player.
My problem is that when one enemy sees the player ALL enemies on the map starts to follow the player.
I cant figure out how to solve this so only the enemy that "see" the player starts to follow him...

Would appreciate any help you guys can give, thank you.



 
n/a

OMC

What a goofball

Registered
  21/05/2007
Points
  3516

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
26th March, 2010 at 18:50:46 -

You'll have to link the sight object with the enemy that shot it.

Try something like:
Start of frame: Spread 0 in Alterable Value A of enemies.

Every half second: Make enemy shoot sight object, set sight object value A to enemy Value A.

*Collision between sight object and player + Sight object Value A = Enemy Value A: Set enemy Alterable value B to 1.

Enemy Value B = 1: Chase player.

You'll likely have to change the order of conditions around a bit on the starred one. I haven't truly got that down pat yet. Don't know if that will work, but it's worth a try!

 

  		
  		

Zip2kx



Registered
  17/05/2003
Points
  32
26th March, 2010 at 19:09:32 -

hmm tried that out, still doesnt work... damn so frustrating lol.

 
n/a

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49566

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
26th March, 2010 at 19:14:26 -

An easier less memory intensive solution would be to have a single invisible detector follow the play, then when it overlaps an enemy, make the enemy start shooting the "sight" objects. When the object touches the play make only the enemy overlapping the detector get alerted.

Not only does this method save memory, but it'll also make it seem like the enemies are communicating with each other about your location, since every enemy overlapping the detector knows your location at once.

 
n/a

Zip2kx



Registered
  17/05/2003
Points
  32
26th March, 2010 at 19:30:51 -

Thanks bro that worked, doesnt it though risk creating some bizzare scenarios if you have some open areas and the enemy is in your line of sight but it doesnt see you because he isnt in the detection area?
Also what is the generally standard method of creating something like this A.I? Is it the method you described?


 
n/a

Sketchy

Cornwall UK

Registered
  06/11/2004
Points
  1970

VIP MemberWeekly Picture Me This Round 43 Winner!Weekly Picture Me This Round 47 WinnerPicture Me This Round 49 Winner!
26th March, 2010 at 20:08:02 -

There are two main methods that people use to make enemies with realistic line-of-sight.

1.) Fastloop Moved Detector
You use a fastloop to move a detector object from the enemy to the player, at a rate of several pixels per loop, and checking for obstacles along the way (using the same maths as you would for 360 degree shooting / movement).

2.) Scaled & Rotated Detector
You horizontally scale an active object (positioned at 0,0 from the enemy) to the distance from the enemy to the player, and then rotate it to the angle between them. If it overlaps an obstacle, then no line of sight exists.

If you search, you will find plenty of articles/examples of both.

In both cases, you should use Pythagoras' theorum to check the distance first, as there's no point checking for a line of sight if the player is out of range.

Edited by Sketchy

 
n/a

Del Duio

Born in a Bowling Alley

Registered
  29/07/2005
Points
  1078

GOTW WINNER CUP 1!GOTW WINNER CUP 2!GOTW WINNER CUP 3!GOTW WINNER CUP 4!Evil klikerHasslevania 2!The OutlawSanta Boot
26th March, 2010 at 20:30:44 -


Originally Posted by UrbanMonk
An easier less memory intensive solution would be to have a single invisible detector follow the play, then when it overlaps an enemy, make the enemy start shooting the "sight" objects. When the object touches the play make only the enemy overlapping the detector get alerted.

Not only does this method save memory, but it'll also make it seem like the enemies are communicating with each other about your location, since every enemy overlapping the detector knows your location at once.



I've used a similar method for the past few games and he's right, it works. I make an invisible active object in the shape of a circle and set the hotspot dead center. Then you always set that circle to the middle of your guy and you have an effective target radius in which the enemy can enter and then start shooting at you or chase you or whatever.

 
--

"Del Duio has received 0 trophies. Click here to see them all."

"To be a true ninja you must first pick the most stealthy of our assorted combat suits. Might I suggest the bright neon orange?"

DXF Games, coming next: Hasslevania 2- This Space for Rent!

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49566

Has Donated, Thank You!Little Pirate!ARGH SignKliktober Special Award TagPicture Me This Round 33 Winner!The Outlaw!VIP MemberHasslevania 2!I am an April FoolKitty
Picture Me This Round 32 Winner!Picture Me This Round 42 Winner!Picture Me This Round 44 Winner!Picture Me This Round 53 Winner!
26th March, 2010 at 21:27:21 -

You could also use the distance formula to stretch a one pixel object between the player and the enemy. If the object overlaps then the alert doesn't happen.

But you need some knowledge of fastloops, so I figured on the easier method.

EDIT: oh yeah, and another useful condition is for these types of situations is "Is "object" getting close to windows edge?"

Edited by UrbanMonk

 
n/a

Zip2kx



Registered
  17/05/2003
Points
  32
26th March, 2010 at 23:55:46 -

thanks dudes, i'll try to figure out the several methods.

 
n/a
   

Post Reply



 



Advertisement

Worth A Click