The Daily Click ::. Forums ::. Klik Coding Help ::. Halp needed
 

Post Reply  Post Oekaki 
 

Posted By Message

Digital Guy



Registered
  12/06/2018 08:25:21
Points
  1
12th June, 2018 at 12/06/2018 08:45:40 -

I'm having trouble finding a way to make a line of sight ai, and cant find any tutorials to help me, can someone help me or send me on the right way?

 
The best of the worst

UrbanMonk

BRING BACK MITCH

Registered
  07/07/2008
Points
  49667

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!
12th June, 2018 at 12/06/2018 15:58:47 -

Well consider an AI that has two states:

-Don't see you
-See you

When they see you they can just move towards you and shoot or something, and when they don't they can just move around randomly and scan for you.

Now for the fun part. How do you determine when they should change states?

Well one way would be to have them shoot and invisible detector towards to the player on an interval (every 10 seconds or so) and then when a detector hits a wall you destroy them, but when it hits the player have the enemy switch to the "See you" state.

When the detector touches the player you can either have all the enemies see you, or just the ones closest to you. You can use a foreach loop to accomplish this along with the distance formula.

Good luck!

 
n/a

The_Antisony

At least I'm not Circy

Registered
  01/07/2002
Points
  1341

VIP MemberStarSnow
2nd October, 2019 at 02/10/2019 10:57:49 -

That's great right up until the point there's 10 enemies all on the screen shooting invisible actives every couple of seconds along with player bullets, and anything else going on at the same time. There are complicated equations for testing line-of-sight, but if you're looking for something easier, the VectoralShape plugin might work.

Instead of testing for hidden active collisions and having to destroy a ton of active objects, add all of your AI enemies to a Qualifier group. Drop VectoralShape into the level editor, then jump into the event editor.

Always:
VectoralShape: Preset Line from X(EnemyQualifierGroup) and Y(EnemyQualifierGroup) to X(Player) and Y(Player). You can also optionally set this event to fire every few seconds if you don't want your enemies constantly testing for line of sight.

Then you can negate a VectoralShape object Overlaps with Backdrop event (so you're testing when the line doesn't overlap a backdrop) which toggles the enemy flag to On. When an enemy in your EnemyQualifierGroup has the same flag toggled on, it should trigger their attention to the player.

Lastly, create an event that tests the VectoralShape object does overlap a backdrop and have it set EnemyQualiferGroup's flag to off, causing them to stop paying attention to the player.

Even if the VectoralShape object doesn't sound like a good idea, I'd recommend taking the tougher route and finding the equation for line-of-sight testing instead of using the active object example Urban mentioned. You should always avoid having more active objects in your game than necessary even if they don't impact performance on your computer. A lot of folks have much older computers than you do, and using as few system resources as possible is always a good idea.



 
ChrisD> Employer: Say, wanna see a magic trick?
ChrisD> Employee: Uhh… sure, boss.
ChrisD> Employer: Your job! It just disappeared! Pack your things and leave! Pretty good trick, huh?
   

Post Reply



 



Advertisement

Worth A Click