How would I make AI that can shoot the player?

I am trying to make a game where there are guards and they are equipped with firearms. If they notice the player, then they will begin to shoot at the player while moving towards them. How would I go about making this feature? I have no clue where to even begin. Let me know if I should provide more detail

1 Like

If you aren’t sure where to start, I would suggest first just getting the guards to move. I am assuming you will want these guards to patrol an area, for which I would recommend using Roblox’s Pathfinding service to achieve this.

From there, once your guards move, you can detect when these guards “see” the player using the dot product of the guard’s position to yours. This video and this thread do a very good job of explaining how it works and how you can use it for your guards.

Now with the ability to check whether the guards have line of sight on you, you can make the guards shoot towards you while using pathfinding service or simply Humanoid:Moveto() to move them slowly to your location. Whether you want your guards to go back to pathfinding when they lose line of sight or infinitely chase you is up to you.

If you want further help we may need more details as to what exactly you want to achieve, since guards that shoot the player on sight is a little vague without context, but I will be happy to help regardless!

1 Like