- Home /
Getting my guard AI to detect fellow guards
Hi there. So I am making a stealth game and my enemies which are the patrolling bad guy guards in this game need to detect each other so they can share information.
I have an idea of using a raycast but as I will explain I am unsure how to implement it.
My enemy AI is currently split into two scripts, one for perception and one for movement, I am adding a third which is for interacting with objects and other guards in the world. Currently the perception script detects the player using a raycast and a field of view angle to get the players distance and position and allow the guard to chase the player via the movement script.
What I would like to do is to add another raycast which would be aimed within the field of view so that if another guard walks in front of it the other guard will be noted as having been seen by a friendly. The reason why is so that I can have patrolling guards who see other guards on patrol notice if one of them doesn't complete their patrol and come back round to where they were last seen.
I understand I need a direction to aim the raycast and therein lies my problem. Each level will have a different amount of guards on it and I would like the ability to scale whether I have 2 guards or 20. I could do a raycast to every other guard in the level but that seems inefficient and I struggle with arrays in C# so I don't know how to use that to my advantage here..
So to sum up I need some way of detecting when another guard comes into the field of view of a guard when there could be as many as 20 separate guards.
Your answer