Hello everyone. In general, I want to do something similar to smart NPCs that will: 1. Be able to shoot at the player when he is in sight. 2. Pass obstacles and go to the place where the player was last noticed. I’m not a very good scriptwriter so I don’t know how to implement this. I already have a gun that the player can hold in his hand
Games that have bots that act like real players usually separate their playermodels and their controllers. I suggest making a custom controller object that the bot has complete control over it, so it can move, shoot, crouch, jump, look around, etc
Another necessity is making your map and gamemode bot-friendly. Having invisible parts that tell the bots the certain use of a spot on the map. For example, you could have a box that is the perfect height for a player to hide underneath. You would put some sort of identifier for that box to tell it apart from a random prop. That identifier will tell the bot it can hide behind that box.
Your bot should also have different states, that are activated dynamically. Like a “just seen player” state, where the bot goes forward and looks for a player, or a state where the bot is just wandering, and a state for any encounters with players.
As for the technical side: use roblox’s built in pathfinding service to facilitate movement for the bot (PathfindingService | Documentation - Roblox Creator Hub). For the controller, you can use a simple script, and using methods in the Humanoid to move the player forward, and jump (:MoveTo()
, .Jump
). The shooting is harder. To make your gun bot-friendly, you need to add a shoot method in the gun that takes in an x value and a y value to tell where the bot is aiming. You will also need to write a method to look around randomly and wander around.
The best starting point is making your systems modular.
I hope this helped you get started! Good luck!
Hi. I kind of want the npc to walk from one point to another, but I still haven’t figured out how to make the npc’s field of view.
This is forum that’s already solved on how to make the NPC FOV.
The solution post has a code excerpt. Using the code, you can get the players in the FOV and do whatever you want with them (like call another function to lock onto them and start shooting)