How could i make a npc fighting system like shell shocked?

Hi i wanted to ask i really want to get a system like the shell shocked npcs they have guns and they try to shoot you and when they get in the trench they use the knifes and meele weapons only if they get really close to you, i tried finding tutorials but i cant find anything

This would be a bit hard, but here is my opinion:

  • Let’s say you have your detection system up and running. You would do a loop for as long as you want.
  • That loop would get nearest player. If the nearest player is closer than the distance you want (using .magnitude on vector3) Then you would tell your npc to equip his knife and start running towards the player and start killing him.

This entirely Depends on your game structure.

Alr but how would i even START with the npc gun system