How can I make my bot/ai open doors?

Hey!

Im currently making a piggy styled game and I have a bot, the bot cannot open doors and thats kinda unfair, because the plays always win and they cant get the experience of getting chased yk. I have no idea on how to make this, so is there a door model that the ai/bot can open or what? Thank you for whoever gives me a answer! And I know very little about scripting so, a video or a explanation would help!

2 Likes

I mean you can technically make a detection system with a Touched() event that opens a door, and closes the door behind it when a TouchEnded() event is ran, but I don’t know if that’s 100% the best option for your scenario.

You can make a sensor block in front of the door or you can just put a script in the door that basically runs a script that when a certain part touches the sensor the CanCollide property is set to false, let me know if you need help writing the script itself.

You could try constantly checking for doors within a certain range and opening them if they are closed and inside that range. But this will look strange if a player keeps opening a door and the script simultaneously opens it.

local PointA = Position
local PointB = Door.Position
local Distance = (PointA - PointB).Magnitude
local Range = 10

if Distance >= Range then
    -- Close door.
end

-- Do note that you'll have to, of course, constantly repeat this process. Which will not be very good performance-wise
-- And this is a very minimal representation. You better off look for scripts in tracking NPCs to learn this better.

If your using pathfinding service you’ll have to have the doors CanCollide off on the server and have them CanCollide on on the client.

1 Like

The way how MiniToon makes his bots are simple, the doors in the server side are actually non-collidable while on the client, it’s collidable. With this advantage, the bot can go through places where the part has CanCollide false, and when the door touched a bot, it will play the animation and the door sound.

2 Likes

I’m working on making a pathfinding module that will allow you to select what parts to include or ignore (like the doors). Hopefully it’ll be ready for you soon, you can watch the development here: Polaris-Nav