Any ideas on how to make a Soldier / Trooper awareness system?

Background:
So, let me give some context. I created some Star Wars trooper armor years ago, and I decided to incorporate them into a new soldier AI.

The Soldier AI is not too complicated. The AI requires a line of sight to detect a target. If it detects a target, it will run towards the target until it reaches firing range. Once it reaches firing range, it will shoot at it while slowly approaching until it gets close enough.

If there is no target, it will go in Patrol. It is very similar to the free model Soldier AI.

Issue:

The problem is that soldier will turn around completely to some soldier who just popped out of the corner of a van while he is 200+ studs away. Not only is that unrealistic, but it’s downright creepy.

I want the Storm Troopers to have some unawareness about them when the troopers aren’t in battle, especially if the enemy is not in their field of view. Of course, they should retain some of it while they are. Essentially, the soldier AI will end up being similar to the Rebels in the game “Evade”

Any ideas on how to go about this mechanic or what route I should take while scripting?

Implement a more realistic and immersive awareness mechanic for your Storm Trooper AI, you can introduce a “Suspicion” or “Awareness” system. This system can determine how aware the Storm Trooper is of its surroundings based on various factors.

here’s some things you could try:

Line of Sight Check:

  • If there’s no direct line of sight to the player, the Storm Trooper’s awareness decreases over time. Use a Raycast or Region3 to check for obstacles between the trooper and the player.

Distance Awareness:

  • The awareness level should decrease as the distance between the Storm Trooper and the player increases. A trooper might not notice a player far away, especially if they are not actively engaged in combat.

Dynamic Patrol Routes:

  • Allow troopers to patrol dynamically instead of following fixed paths. This way, they might not always face the same direction, kind of like juking.

Audio Awareness:

  • Implement a system where loud noises or gunfire increase awareness temporarily, making the trooper more alert.
for _,Humanoid in pairs(humans) do
			local root = Humanoid.RootPart
			if root and (Humanoid.Health > 0) and (checkDist(root,zombie.root) < dist) and (not Humanoid:HasTag("Zombie")) then
				dist = checkDist(root,zombie.root)
				table.insert(potentialTargets, Humanoid)
			end
		end

		if #potentialTargets > 0 then 
			--print(zombie.Character.Name.." has found potential targets")
			for _,targetHumanoid in pairs(potentialTargets) do
				local zombieToHuman = (targetHumanoid.Parent.Head.Position - zombie.Character.Head.Position).Unit

				if zombieToHuman:Dot(zombie.Character.Head.CFrame.LookVector) > 0.2 then
					table.insert(targetsInFov, targetHumanoid)
				end
			end
		end

		if #targetsInFov > 0 then
			--print(zombie.Character.Name.." has found targets in FOV")
			for _,targetHumanoid in pairs(targetsInFov) do
				local raycastParams = RaycastParams.new()
				local Zombies = {}
				for i,v in ipairs(CollectionService:GetTagged("Zombie")) do
					table.insert(Zombies, v.Parent)
				end
				raycastParams.FilterDescendantsInstances = {Zombies}
				raycastParams.FilterType = Enum.RaycastFilterType.Exclude
				local raycastResult = workspace:Raycast(zombie.Character.Head.Position, targetHumanoid.Parent.Head.Position - zombie.Character.Head.Position, raycastParams)	

				if raycastResult then
					if raycastResult.Instance:IsDescendantOf(targetHumanoid.Parent) then
						table.insert(targetsInSight, targetHumanoid.RootPart)
					end
				end
			end
		end

		if #targetsInSight > 0 then 
			dist = 200
			for _,targteRoot in ipairs(targetsInSight) do
				if (zombieroot.Position - targteRoot.Position).magnitude < dist then
					target = targteRoot
					dist = (zombieroot.Position - targteRoot.Position).magnitude
				end
			end
		end

This is from one of my AI scripts.
You can see that I first get players in a close proximity and put them in a PotentialTarget list.
I then use some math to get players in the FOV of the AI and put them in a TargetInFOV list.
I then raycast to every targets in TargetInFOV and put the players detected by the raycast in a TargetsInSIght list.
Finally, I sort the TargetsInSight to get the closest target.

These are really good! Thank you.

Yeah, this could definitely help me figure out how to have troopers utilize an FOV mechanism. That LookVector bit looks interesting. I dont know much about :Dot() but I’ll definitely check it out.