Hey, I am trying to make a game, I need an NPC that can complete advanced parkour courses (not extremely advanced, i just mean like at least be able to jump over a gap, which the default PathfindingService doesn't do.) Can this do jumps?
Fair warning id watch another video on Pathfinding Parameters because it helps with making the AI jump and doge certain blocks. (like kill bricks etc.) and plus the fact it is not covered here.
@@YeaIDoStuff Yes, i didn’t cover the standard settings. However when calling the API, in the settings table you can set those settings using the key [“StandardPathfindSettings”]
I’ve used this for my game and I just wanted to say a massive thanks I put this in my first devlog on my channel but didn’t shout u out but in my next vid I will because this was so helpful
Alright so i just checked it out, the forbidden api also has some other really convenient stuff including the Ai stuff. Im talking math, datastoring, and some misc stuff. I really recommend you check it out if you just wanna make a game without dealing with annoying BS that would slow down the production of a pretty small game drastically. edit: the AI can be really janky. it does not like to jump, so much so that it would rather give up and stand in place instead of it. Be careful if you going to use it on a map with jumpable obstacles with multiple turns
Hey Critixx! I thank you so much for this script and it has saved me hours. I do have one question. Do you think you will be willing to help me make it so the ai will recognize what a door is and will have a function to open it and also play an animation? There is just so much to this path-finding complicated group of scripts that I don't understand. I don't know where to even start to add this function. If you don't want to help fine with me! You have done plenty! Love your content and keep it up!
Unfortunately that’s rather complicated since that would involve making your own pathfinding system. The way around it would most likely be to make the doors non-collidable on the server side (make sure the client is) and then whenever it touches the door check if it is open or do an animation (the ai will then consider it in the shortest path) Edit: as long as you are confident enough in your coding ability to be able to signal a stop in the ai as it approaches a door and then restart it once it is open you should be able to do this
I think I have a solution for you... You can set the destination to the door, then make a large invisible, anchored, collision off block around it, then add a part into a script that when it touches the invisible area, it will teleport slightly to the correct space, anchor itself, play the animation to open the door, then change the destination to directly through the door, then set another destination after that to its end goal. :)
hey dude if you can can it be possible for sight distance so it wanders around going around then when you get into its sight it chases you then stops after a while
There's a flaw. For tracking players, if the NPC has a fast WalkSpeed (30-100) and gets close to the player, it slows down and doesn't maintain the fast speed.
So this is not an issue with the API. You need to use the antilag script included or just put in a simple server script with this code NPCHumanoidRootPart:SetNetworkOwner(nil)
does this work to make a car pathfind to an object and repeat driviing around the map? I really want to make a car drive around the map on roads so i hope this model can do that. a tut would be nice pls.
No, and unfortunately I cannot make a tutorial. My recommendation would be to use the pathfinding API from roblox and use tweens and lerps to move the car.
I watched to the end and you said you would be making an advanced tutorial later but were is it? great tutorial I just need it to locate the nearest player
So i will but here’s how to do that. Loop through all players ( for i, player in pairs(game.Players:GetChildren()) do ), store two variables, nearPlayer and nearDist. To get distance do (pos1 - pos2).magnitude Should be simple from there
@@CritDEV its a little confusing so I was wondering about you making a video on this and also how do I fix when a player dies the AI doesnt detect them?
Hey Critixx, nice vid. btw i have 2 question: 1- how do i get rid of the purple balls of tracking? 2- how do i make him follow a player in a certain radius, let's say 30 block radius? please answer as quickly as possible , i have a school project to do and i'm doing it in roblox
@@CritDEV Sorry to bother you, but how do i do it? How to detect if a player respawns using "charadded"? I'm a beginner who is looking forward to create a horror game.
he doesn't because there is a typo in the code. In line 11 he should've written: ai.SmartPathfind(NPC, game.Players...) He wrote it with a dot instead of a coma
I'll see what i can do since im a beginner it'll be kinda difficult for me to add stuff like the extra things that i want im making a realistic shooter game to shoot zombies
Would it be possible to make a flee function for the API. I haven't actually used the API yet so this might already be a feature but it doesn't look like it's in the API.
I believe that’d be easy to code yourself. Save any location you would want it to flee to then pathfind it to that location without tracking. You could also make a part for it to track and then move that part where you want it to go
@@CritDEV (I don't mean wander when I say flee) I have a bunch of maps and it would take a long time for me to add a bunch of flee points to all of them. Is there a way that I could automate the process?
Oh yeah, also thanks for the ai module man. I'm not really a fan of free models but I'm starting to like module scripts. They spare a lot of time and you still need to do the stuff. Like, you have the pathfinding script and everything, but you still need to code the behavior of your ai, it's very customizable and I'm loving it, thank you for your service! I'll make sure to credit your work in my game :)
@@CritDEV I can't seem to find the chase ai video that you're talking about But anyways I think I can achieve similar results with the raycast fov video you made. You get all of the players, check if one of them is inside the ai specified range. Then, check if the player humanoid root part (or whatever part you assign in the script) is in range of the ai fov. If it is, then start chasing the player.
Anything on having the AI stop targeting the player when dead? Currently trying to fix that but it seems that I cant stop the targeting on that same dead player.
I think I found a problem my 7 stud high Rig won't jump a 3 or 4 stud high jump. It will just sit there where it should of jumped but as soon as I make the jump 5 studs it will jump. I have tried changing the AgentHeight and I made sure that AgentCanJump is true
I don't know why but when it visualize it just stops at the second point of the visual but when it just has to use line of sight or when the part is close. It has no problems
here is my code local RS = game:GetService("ReplicatedStorage") local Forbidden = RS:WaitForChild("Forbidden") local AI = require(Forbidden:WaitForChild("AI")) local target = workspace:WaitForChild("target") local NPC = workspace.Rig AI.SmartPathfind(NPC,target,true,{AgentCanJump = true,Visualize = true,Tracking = false})
It works for the part but when I change it to look for the player it doesn't work. I don't know why. The rig is R6 and my character is R15 is this the issue?
@@CritDEV actually, it was the problem. I changed it to R6 only in the game settings and it was fixed. Thanks for the help, the video was very helpful!
@@CritDEV Hi, I'm trying to make a zombie game, but something isn't working right with your model. It turns out that I have a killer and I change the name "Humanoid" to "Zombie" and it doesn't work. Could you help me please?
@@Fexxies do not rename the Humanoid, i believe the property you are looking to change inside of the humanoid is called DisplayName edit: even if this is not what you are trying to do, you should not have to rename the humanoid under any circumstance. please join the discord if you need help.
i would like to know more about ai , could you not only make a video about all commands about the api and also make tutorials about ai? you seem like a dude who knows
Make a loop. If the targeted player is different than the new closest player than call ai.stop(NPC) and ai.SmartPathfind(NPC, newtarget , etc…) Simple loops, must be in a server script, I recommend using runservice.PhysicsStepped:Wait() as the delay in the loop
It will go for the destination part thing but when i try it on players it says me " No path could be found. This is an issue with Roblox, not Forbidden. The NPC might also not be able to fit where the waypoint is, please see 'AgentRadius' " and I do not understand it!
@@G102theChair well in that case, the only way I can help is by saying to make sure the space the AI is trying to go to is at least 6 studs if you do not change the StandardPathfindSettings.
I do not know. It is hard coded to do so from Roblox’s pathfinding system. You can externally trigger a jump by placing a part where it commonly gets stuck and when the AI touches it set Jump in the humanoid to true
I noticed in the AI modulescript that there's a los(line of sight) check. Any idea on how to actually use it? I'm trying to make it call ai.Stop(NPC when line of sight is gained, but I can't figure out how. If I put ai.Stop(NPC) into a loop and if statement, it says that ai is outside the active table. I have a sneaking suspicion that there's already a way and that I'm just being stupid. edit: I also noticed that it's actually already being called, but I can't figure out where. I placed a print statement and it prints, but I cannot find the place where losCheck is being called.
@@animebinger7974 just in case you are planning it. Tracking mode automatically switches to the normal MoveTo call instead of pathfinding when the NPC is in line of sight
Here is my comment as a roblox developer saying this is great. now because 9/10 coders already recommended this, it is my obligation to NOT recommend this because I am the 1/10 >:D (Also, please add support for inputting a vector3 value instead of only takin in instances, thank you)
@@CritDEV oh i know i tried that but it is changing the walk speed but i think it stops for like 2 ms because i checked and the walk speed didn't change. How can i change it so it doesen't stop and reach the player?
for some majestic reason if i try to call the SmartPathfind function then i get an error saying something along the lines of "SmartPathfind is not a valid member of module script "AI"" and it doesn't work at all. does anyone know why this is happening? I even tried copying the EXACT code in the video and i got the same issue
@@CritDEVnevermind this time it still doesn't work, but there are no errors. and the path doesn't get visualized even when i set that value to true, does the API work with custom made characters or is it just for regular R6 and R15 roblox npcs?
@@CritDEV everything is unanchored, it has a humanoid, it has all the necessary Motor6Ds, it functions like an npc should. could there be any other reason why the api does not work? did it by any chance get broken recently due to roblox updates?
So I figured it out. So what you have to do is simply put the "Animate" script that you would find in the player or when you spawn a Rig via roblox and convert it into a server script.
@@ITssShawnVr it should work, just provide the correct StandardPathfindSettings if the size is different, For details on what should be provided in that table, see Roblox’s “Character Pathfinding”
Do a loop to get (playerpart - enemy part).magnitude for each one. Store the current closest player and distance and at the end of the loop you’ll have your target. You can also have a loop running in the background to detect if the closest player changed and call API.stop(enemy) and reset it.
isnt possible with the api. try this tho! local Forbidden = game.ReplicatedStorage.Forbidden local AI = require(Forbidden.AI) local function GetNearestPlayer() local CurrentPlayer = nil for _,v in pairs(game.Players:GetChildren()) do if v:IsA("Player") then if CurrentPlayer == nil then CurrentPlayer = v.Character else if CurrentPlayer.HumanoidRootPart.Position.Magnitude < v.Character.HumanoidRootPart.Position.Magnitude then CurrentPlayer = v.Character end end end wait(.025) end return CurrentPlayer end wait(1) while wait(1) do local Player = GetNearestPlayer() wait(.5) AI.SmartPathfind(script.Parent, Player, false, {Visualize = false, Tracking = false}) end (put forbidden in replicatedStorage)
@@CritDEV i fix all of that but how can i stop the NPC instantly local rs = game:GetService("ReplicatedStorage") local forbidden = rs:WaitForChild("Forbidden") local ai = require(forbidden:WaitForChild("AI")) local NPC = script.Parent local function RandomLocation() local locations = { workspace.Points.Part1, workspace.Points.Part2, workspace.Points.Part3, workspace.Points.Part4, workspace.Points.Part5, workspace.Points.Part6, workspace.Points.Part7, workspace.Points.Part8, workspace.Points.Part9, workspace.Points.Part10 } return locations[math.random(1, #locations)] end local target = RandomLocation() while true do wait(0.1) if script.Parent.Status.Walking.Value == true then ai.SmartPathfind(NPC,target,true,{Visualize = true, Tracking = false}) target = RandomLocation() else print("NPC Stop walking") ai.Stop(NPC) end end
don’t know what you mean by go toward different waypoints but for the damage you just put a script inside the HRT and do local db = false - stops script from running thousands of times a second local damageCooldownTimer = 1 - seconds HRT.Touched:Connect(function(hit) local enemyChar = nil if hit.Parent:FindFirstChild(“HumanoidRootPart) then enemyChar = hit.Parent end if hit.Parent.Parent:FindFirstChild(“HumanoidRootPart) then enemyChar = hit.Parent.Parent end if enemyChar == nil then return end db = true - damage code here wait(damageCooldownTimer) db = false end)
There is a yield setting when you call the function. Yielding is basically where it will stop further execution of the lines of code after the function call if true. Just make it so that it’s a loop and pathfinds between those locations after the previous pathfind finishes
I did everything right but it didn't work the dummy was unanchored aswell. Any help?: local rs = game:GetService("ReplicatedStorage") local forbidden = rs:WaitForChild("Forbidden") local ai = require(forbidden:WaitForChild("AI")) local NPC = script.Parent local target = workspace.dest wait(2) ai.SmartPathfind(NPC,game.Players:GetChildren()[1],true,{Visualize = true, Tracking = true})
I believe I have somewhere in the settings the default pathfinding settings, in there set AgentCanJump to true. If it isn’t jumping it could also be due to the humanoids jump power
whyyyyy do I always need to download something suspicious??!?!?!?! Please just make a full tutorial instead of making everyone download some random model or plugin!
CritDev my comments keep disapearing for some reason on your reply so can you continue on here: i changed it but it doesnt work I put a video on my channel showing the issue though
Also for future reference in case you ever need it. Making a video not made for kids does not mean 13+, 18+, etc... it only allows for features like commenting and such and recommends videos for different audiences.
@@CritDEV oh my bad I didnt know. but heres the call its simple really: ai.SmartPathfind(troop, hit, true, {Visualize = true, tracking = true}) the troop being the npc, and hit being the part the mouse hit. and I tried playing around with changing SwapMovementMethodDistance in the settings table but nothings changing
@@chosenone3 in a day or so I will have tested and pushed a new version of the AI module, completely rewritten. I’m not going to rush it and I’m going to make sure it’s fully tested but it is “developed” The issue is random problems which make pathfinding asynchronously the most annoying thing I’ve ever dealt with.
you guys need it to chase you even after it respawns: here! local rs = game:GetService("ReplicatedStorage") local forbidden = rs:WaitForChild("Forbidden") local ai = require(forbidden:WaitForChild("AI")) local NPC = script.Parent local targetPlayer = nil -- To keep track of the target player -- Function to start AI pathfinding local function StartPathfinding() ai.SmartPathfind(NPC, targetPlayer, true, {Visualize = true, Tracking = true}) end -- Function to stop AI pathfinding local function StopPathfinding() ai.Stop(NPC) end -- Function to handle player character added event local function OnCharacterAdded(character) -- Update target player to the newly added character's player targetPlayer = game.Players:GetPlayerFromCharacter(character) -- Start pathfinding StartPathfinding() end -- Connect the player character added event game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(OnCharacterAdded) end) game.Players.PlayerRemoving:Connect(function(player) if player == targetPlayer then -- Player has left, stop pathfinding StopPathfinding() end end) -- Start initial pathfinding StartPathfinding() thank me later
@@Lennypennyez Thanks man. I was able to modify that script and have it working as expected for me. (UPDATE 2) local rs = game:GetService("ReplicatedStorage") local forbidden = rs:WaitForChild("Forbidden") local ai = require(forbidden:WaitForChild("AI")) local NPC = script.Parent local root = NPC.HumanoidRootPart local targetPlayer = nil local newtargetPlayer = nil local db = false local db1 = false function FindNearestPlayer() local minDistance = math.huge local nearestPlayer = nil for _, player in ipairs(game:GetService("Players"):GetPlayers()) do local character = player.Character if character and character:FindFirstChild("Humanoid") and character.Humanoid.Health > 0 then local distance = (character.HumanoidRootPart.Position - root.Position).Magnitude if distance < minDistance then minDistance = distance nearestPlayer = player end end end return nearestPlayer end function StartPathfinding() while wait(1) do if db then return end db = true local bot = NPC:FindFirstChild("Bot") local botState = bot:GetState() if botState == Enum.HumanoidStateType.Seated or botState == Enum.HumanoidStateType.Swimming then task.wait(math.random(0.25, 1.5)) bot:ChangeState(Enum.HumanoidStateType.Jumping) end wait() newtargetPlayer = FindNearestPlayer() if newtargetPlayer and newtargetPlayer == targetPlayer then if targetPlayer and targetPlayer.Character then ai.SmartPathfind(NPC, targetPlayer.Character, false, {Visualize = false, Tracking = true}) end end wait() if newtargetPlayer and newtargetPlayer ~= targetPlayer then StopPathfinding() targetPlayer = newtargetPlayer if targetPlayer and targetPlayer.Character then ai.SmartPathfind(NPC, targetPlayer.Character, false, {Visualize = false, Tracking = true}) end end --wait(5) db = false end end function StopPathfinding() ai.Stop(NPC) end function OnPlayerRemoving(player) if player == targetPlayer then StopPathfinding() end end function OnCharacterRemoving(character) local player = game.Players:GetPlayerFromCharacter(character) if player == targetPlayer then StopPathfinding() player.CharacterAdded:Connect(function(newCharacter) OnCharacterAdded(newCharacter) end) end end function OnCharacterAdded(character) targetPlayer = game.Players:GetPlayerFromCharacter(character) if targetPlayer and targetPlayer.Character then targetPlayer.Character:WaitForChild("Humanoid").Died:Connect(function() OnCharacterRemoving(targetPlayer.Character) end) end StartPathfinding() end function OnNPCSpawned() if targetPlayer and targetPlayer.Character then StartPathfinding() end end game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(OnCharacterAdded) end) game.Players.PlayerRemoving:Connect(OnPlayerRemoving) NPC.ChildAdded:Connect(function(child) if child:IsA("Humanoid") then OnNPCSpawned() end end) for _, player in ipairs(game:GetService("Players"):GetPlayers()) do if player.Character then targetPlayer = player player.Character:WaitForChild("Humanoid").Died:Connect(function() OnCharacterRemoving(player.Character) end) StartPathfinding() end player.CharacterAdded:Connect(OnCharacterAdded) end
I have a pathfinding bug when handling with multiple enemies with one script. I am currently finding a fix at the moment. If you have any ideas or suggestions let me know. Here’s a video th-cam.com/video/ec6feocxMhA/w-d-xo.html
Update: I have found a general fix for this. While looping through the waypoints, I am skipping the first 5 waypoints to prevent the enemy from jittering
@@CritDEV no, I understand coding, I just didn’t understand where to put the scripts, you said to put it in replicated storage, but what about the NPC?
Link to API
www.roblox.com/library/11229474803/Forbidden-API-OFFICIAL
Common issues in replies.
Enjoy making your game!
It is forbidden to unsubscribe to you
Hey, I am trying to make a game, I need an NPC that can complete advanced parkour courses (not extremely advanced, i just mean like at least be able to jump over a gap, which the default PathfindingService doesn't do.) Can this do jumps?
@@HeroDevv it uses the default pathfinding service, but only simplifies it
Fair warning id watch another video on Pathfinding Parameters because it helps with making the AI jump and doge certain blocks. (like kill bricks etc.) and plus the fact it is not covered here.
@@YeaIDoStuff Yes, i didn’t cover the standard settings. However when calling the API, in the settings table you can set those settings using the key [“StandardPathfindSettings”]
You are a life saver. Devs like you are heroes.
I wouldnt say so he uses a kit basically everyone can do this
@@maciezez you know he made the kit SO that everyone can do this right?
I came here by watching yt shorts
Same
Bawls same!
Sqme
Same
Same
Homie I am your 500th sub, thank you for this btw its great.
I’ve used this for my game and I just wanted to say a massive thanks I put this in my first devlog on my channel but didn’t shout u out but in my next vid I will because this was so helpful
Just waitin till u EXPLODE WITH SUBS brooo this is AHHMAZING!
very cool lookin forward to updates
THIS MAN IS HEAVILY UNDERRATED!
You saved my game! This is going to help me so much.
This was so helpful tysm 😭
This is incredible, thank you friend, I will make the most of it.
How did you get it to work can you paste the code?
Alright so i just checked it out, the forbidden api also has some other really convenient stuff including the Ai stuff. Im talking math, datastoring, and some misc stuff. I really recommend you check it out if you just wanna make a game without dealing with annoying BS that would slow down the production of a pretty small game drastically.
edit: the AI can be really janky. it does not like to jump, so much so that it would rather give up and stand in place instead of it. Be careful if you going to use it on a map with jumpable obstacles with multiple turns
Hey Critixx! I thank you so much for this script and it has saved me hours. I do have one question. Do you think you will be willing to help me make it so the ai will recognize what a door is and will have a function to open it and also play an animation? There is just so much to this path-finding complicated group of scripts that I don't understand. I don't know where to even start to add this function. If you don't want to help fine with me! You have done plenty! Love your content and keep it up!
Unfortunately that’s rather complicated since that would involve making your own pathfinding system.
The way around it would most likely be to make the doors non-collidable on the server side (make sure the client is) and then whenever it touches the door check if it is open or do an animation (the ai will then consider it in the shortest path)
Edit: as long as you are confident enough in your coding ability to be able to signal a stop in the ai as it approaches a door and then restart it once it is open you should be able to do this
Alright. Again, I really appreciate it
@@CritDEV
@@YoungBassAngler Use raycast, and if in the ray it will detect if there is a part called "Door" if so it will proceed with a tween to open the door.
I think I have a solution for you... You can set the destination to the door, then make a large invisible, anchored, collision off block around it, then add a part into a script that when it touches the invisible area, it will teleport slightly to the correct space, anchor itself, play the animation to open the door, then change the destination to directly through the door, then set another destination after that to its end goal. :)
hey dude if you can can it be possible for sight distance so it wanders around going around then when you get into its sight it chases you then stops after a while
Use the apis line of sight function
it dont work {Visualize = true, Tracking = true}) has a red line under it and it dont work
hey i have the same problem did you figure it out yet?
There's a flaw. For tracking players, if the NPC has a fast WalkSpeed (30-100) and gets close to the player, it slows down and doesn't maintain the fast speed.
There should be a parameter for swapping the method of movement @ x distance in settings. I’ll check soon
So this is not an issue with the API. You need to use the antilag script included or just put in a simple server script with this code
NPCHumanoidRootPart:SetNetworkOwner(nil)
@@CritDEV I remember doing that with my NPCs I forgot to add that. I appreciate the response, my man.
does this work to make a car pathfind to an object and repeat driviing around the map? I really want to make a car drive around the map on roads so i hope this model can do that. a tut would be nice pls.
No, and unfortunately I cannot make a tutorial.
My recommendation would be to use the pathfinding API from roblox and use tweens and lerps to move the car.
I think u broke something in an update as im getting this error "Unable to assign property Value. Object expected, got PathWaypoint "
Remember guys best pathfinding agorithm is always the integrated ones with your own waypoints
is the module broken or is it just me
i get an error from the module on line 139 saying
attempt to index nil with 'StandardPathfindSettings'
My fault i accidentally put .Position at the end of the target arguement instead of the instance itself
When i have it set to go to a part it will move for a second then stop, if I make it follow me it only moves when I move, how do I fix this?
How would you know when the model has reached its endpoint?
I watched to the end and you said you would be making an advanced tutorial later but were is it? great tutorial I just need it to locate the nearest player
So i will but here’s how to do that.
Loop through all players ( for i, player in pairs(game.Players:GetChildren()) do ),
store two variables, nearPlayer and nearDist.
To get distance do (pos1 - pos2).magnitude
Should be simple from there
@@CritDEV Thx
@@CritDEV its a little confusing so I was wondering about you making a video on this and also how do I fix when a player dies the AI doesnt detect them?
@@BlankJuice the ai needs to be restarted whenever a new character is created
@@CritDEV okay
Hey Critixx, nice vid. btw i have 2 question:
1- how do i get rid of the purple balls of tracking?
2- how do i make him follow a player in a certain radius, let's say 30 block radius?
please answer as quickly as possible , i have a school project to do and i'm doing it in roblox
1: Just set visualize to false
2: Run a loop and do if (Player.Character.HumanoidRootPart - NPC.HumanoidRootPart).magnitude
@@CritDEV no thank you the video was helpful and so were you. thank you so much
@@CritDEV Where do i put the loop? And the code you said
@@RoyaItee unfortunately since I do not know what you are doing I’m unable to really help. I’d highly encourage you to watch a Lua tutorial.
@@CritDEV I made comment, so basically kind of like a zombie following you when u get in a distance from it
You should fix the part where when the NPC chases the player, and kills the player and the player respawns, it stops chasing with the player
That’s a feature in my opinion. You can add that yourself by detecting when a player respawns using charadded
@@CritDEV It works well, but now when the NPC dies, it doesn't chase any players after it respawns.
@@CritDEV Sorry to bother you, but how do i do it? How to detect if a player respawns using "charadded"? I'm a beginner who is looking forward to create a horror game.
@@AdvancedAnimator Player.CharacterAdded:Connect(function() - code end)
local rs = game:GetService("ReplicatedStorage")
local forbidden = rs:WaitForChild("Forbidden")
local ai = require(forbidden:WaitForChild("AI"))
local NPC = script.Parent
local target = workspace.dest
wait(2)
wait(2)
ai.SmartPathfind(NPC.game.Players:GetChildren()[1],true,{Visualize = true, Tracking = true})
wait(10)
ai.Stop(NPC)
wait(1)
ai.SmartPathfind(NPC, game.Players:GetChildren()[1], true, {Visualize = true, Tracking = true})
Not all heros wear capes💯💯
he doesn't because there is a typo in the code. In line 11 he should've written: ai.SmartPathfind(NPC, game.Players...)
He wrote it with a dot instead of a coma
this is great, but for some reason the pathfinding takes a while to work when the script that calls it is enabled.
I'll see what i can do since im a beginner it'll be kinda difficult for me to add stuff like the extra things that i want im making a realistic shooter game to shoot zombies
So it says No path could be found. This is an issue with Roblox, not Forbidden.
Would it be possible to make a flee function for the API. I haven't actually used the API yet so this might already be a feature but it doesn't look like it's in the API.
I believe that’d be easy to code yourself. Save any location you would want it to flee to then pathfind it to that location without tracking. You could also make a part for it to track and then move that part where you want it to go
@@CritDEV (I don't mean wander when I say flee) I have a bunch of maps and it would take a long time for me to add a bunch of flee points to all of them. Is there a way that I could automate the process?
Can you make it so it only see a player and tracks him down if he is in sight and not behind a wall for example?
@@OhHaiC go to the Chase AI video on my channel for the premade solution.
By default it does that
@@CritDEVIs it the ray cast fov video?
Oh yeah, also thanks for the ai module man. I'm not really a fan of free models but I'm starting to like module scripts. They spare a lot of time and you still need to do the stuff.
Like, you have the pathfinding script and everything, but you still need to code the behavior of your ai, it's very customizable and I'm loving it, thank you for your service! I'll make sure to credit your work in my game :)
@@OhHaiC yeah you can use that if you want to create the AI yourself. ChaseAI I would look into to see if it does what you need.
@@CritDEV I can't seem to find the chase ai video that you're talking about
But anyways I think I can achieve similar results with the raycast fov video you made. You get all of the players, check if one of them is inside the ai specified range. Then, check if the player humanoid root part (or whatever part you assign in the script) is in range of the ai fov. If it is, then start chasing the player.
Had some trouble at first but here is the script I used that finally got it tracking if anybody else is having trouble
local rs = game:GetService("ReplicatedStorage")
local forbidden = rs:WaitForChild("Forbidden")
local ai = require(forbidden:WaitForChild("AI"))
local NPC = script.Parent
wait(2)
wait(2)
ai.SmartPathfind(NPC, game.Players:GetChildren()[1],true,{Visualize = true, Tracking = true})
wait(10)
ai.Stop(NPC)
wait(1)
ai.SmartPathfind(NPC, game.Players:GetChildren()[1], true, {Visualize = true, Tracking = true})
Anything on having the AI stop targeting the player when dead? Currently trying to fix that but it seems that I cant stop the targeting on that same dead player.
Simply get player.Character.Humanoid.Health
I think I found a problem my 7 stud high Rig won't jump a 3 or 4 stud high jump. It will just sit there where it should of jumped but as soon as I make the jump 5 studs it will jump. I have tried changing the AgentHeight and I made sure that AgentCanJump is true
Maybe try increasing the jump power? It’s in the humanoid
I don't know why but when it visualize it just stops at the second point of the visual but when it just has to use line of sight or when the part is close. It has no problems
That’s weird. Send a video if you can of it happening
@@CritDEV The same thing happened to me
There is this error : Unable to assign property Value. Object expected, got PathWaypoint
@@Cocodado send the code you had when the error happened
@@CritDEV Anyways, it's working now.
Make yourself: ❌️
Use a API that can broke code in future: ✅️
Hey there. Do you think it’s possible you can create a function that can return if the path is passable?
Yeah I would save the location from where the pathfind started and repathfind to that location.
I believe it accepts Vector3’s
@@CritDEV never mind I looked at your code and it’s very simple to do. Sorry but thank you for the help!
@@masterwallace4268 good luck! let me know if you find any bugs
@@CritDEV yo does this work on r6 models?
@@badprong2556 should
I built a rig and done what you did, but still nothing worked
Unfortunately the API seems to work half the time. I’d recommend finding a path finding tutorial else where
How do i remove the purple line? (fixed now)
Thank you! quick question though, how do i make it stop so hes not like rubbing against me?
oh also put another script that sets the HumanoidRootPart:SetNetworkOwner(nil)
idk if that’s in the tutorial but it prevents lag
@@CritDEV Okay! Thanks.
i did exactly what you did but it doesnt work. my dummy stay on the place and do nothing
@@Dave-r1j join discord for support or message errors
this is amazing and all but how do i make it track and follow a player? because i wanna use this for my game
you call it with the target as the player and tracking on true
@@CritDEV ok thx i will try this tomorrow
The player pathfinding doesnt work its saying the forbidden ai attempt to index nil with ‘position’
You are passing an object or thing that no longer exists
hi, this is a really helpful video bc i hate roblox's pathfinding system. however, i'm not sure how to see when my NPC has gotten to its target part.
@@quinvzy you can use .Touched on the part.
Later on Forbidden will include events to hook to as such
@@CritDEV thank you
this is awesome but it says “attempt to index nil with ‘position’” on line 279
Mine just flat out doesnt work at all
I changed the jump power both up and down and still not jumping over 3 or 4 stud high blocks.
here is my code
local RS = game:GetService("ReplicatedStorage")
local Forbidden = RS:WaitForChild("Forbidden")
local AI = require(Forbidden:WaitForChild("AI"))
local target = workspace:WaitForChild("target")
local NPC = workspace.Rig
AI.SmartPathfind(NPC,target,true,{AgentCanJump = true,Visualize = true,Tracking = false})
how do i make it unlaggy with track on cuz i dont know what u meant by using setnetworkowner and how to setup tha antilag so would u help me?
HumanoidRootPart:SetNetworkOwner(nil) in a regular script
Make sure you use WaitForChilds and etc…
@@CritDEV thank you though didnt help but i think it will be fixed in new updates (atleast i hope) =D
Does it work ignoring all parts that can collide are false? So they can walk through it
Yeah I think thats a Roblox feature for the Pathfinding Service
It works for the part but when I change it to look for the player it doesn't work. I don't know why. The rig is R6 and my character is R15 is this the issue?
@@arctalgamez that should not be the problem. Please join the discord for help
@@CritDEV actually, it was the problem. I changed it to R6 only in the game settings and it was fixed. Thanks for the help, the video was very helpful!
@@CritDEV Hi, I'm trying to make a zombie game, but something isn't working right with your model. It turns out that I have a killer and I change the name "Humanoid" to "Zombie" and it doesn't work. Could you help me please?
@@Fexxies do not rename the Humanoid, i believe the property you are looking to change inside of the humanoid is called DisplayName
edit: even if this is not what you are trying to do, you should not have to rename the humanoid under any circumstance. please join the discord if you need help.
didn't work for me.
By the way character makes too much lag somehow. how to fix it i need a reply for this, pls
Please drag and drop the included AntiLag script into your npc :).
@@CritDEV bro me and my friend tried to fix it and it worked and thank you so much for the ai bro🤯🙏
In your short you said only one line of code but there is definite more than one line
@@Blockhead743 it’s one line of code. It’s just best practice not to make it one line and abstract your variables like the module, NPC, and target.
i would like to know more about ai , could you not only make a video about all commands about the api and also make tutorials about ai? you seem like a dude who knows
maybe depends on what happens in my life. If I have time and I’m not sick I’ll do it
Is there a way to change the target while pathfinding (chase the nearest player)?
Make a loop. If the targeted player is different than the new closest player than call ai.stop(NPC) and ai.SmartPathfind(NPC, newtarget , etc…)
Simple loops, must be in a server script, I recommend using runservice.PhysicsStepped:Wait() as the delay in the loop
@@CritDEV thank you
How can I make it constantly update to the new part's position if the part moves?
Set tracking to true
@@CritDEV thx
Full of bugs when It requires jumping
It will go for the destination part thing but when i try it on players it says me " No path could be found. This is an issue with Roblox, not Forbidden. The NPC might also not be able to fit where the waypoint is, please see 'AgentRadius' " and I do not understand it!
@@G102theChair
the error is basically saying that Roblox’s pathfinding solution could not reach the target.
please join discord for more help.
@@CritDEV I don't have discord.
@@G102theChair well in that case, the only way I can help is by saying to make sure the space the AI is trying to go to is at least 6 studs if you do not change the StandardPathfindSettings.
@@CritDEV Ah the problem was the spawnpoint, it spawns my character in mid air.
Sometimes the NPC doesn't jump, how can I fix that?
I do not know. It is hard coded to do so from Roblox’s pathfinding system.
You can externally trigger a jump by placing a part where it commonly gets stuck and when the AI touches it set Jump in the humanoid to true
The script won't work with a mesh, would it?
It will as long as it has a Humanoid and a HumanoidRootPart
@@CritDEV alright, thank you (:
I noticed in the AI modulescript that there's a los(line of sight) check. Any idea on how to actually use it? I'm trying to make it call ai.Stop(NPC when line of sight is gained, but I can't figure out how. If I put ai.Stop(NPC) into a loop and if statement, it says that ai is outside the active table.
I have a sneaking suspicion that there's already a way and that I'm just being stupid.
edit: I also noticed that it's actually already being called, but I can't figure out where. I placed a print statement and it prints, but I cannot find the place where losCheck is being called.
std.Math.LineOfSight
Make sure to require the std module or just the math module
@@CritDEV Holy crap ty!
@@animebinger7974 just in case you are planning it. Tracking mode automatically switches to the normal MoveTo call instead of pathfinding when the NPC is in line of sight
@@CritDEV Yea I found that surprising. Forbidden is amazing c:
Here is my comment as a roblox developer saying this is great. now because 9/10 coders already recommended this, it is my obligation to NOT recommend this because I am the 1/10 >:D (Also, please add support for inputting a vector3 value instead of only takin in instances, thank you)
support is coded I’ll push it soon along with a new datastore system
How do you make it so it is speeder than the player ? how do you change the walkspeed?
@@SuperFenix164 change the WalkSpeed inside the Humanoid of the NPC
@@CritDEV oh i know i tried that but it is changing the walk speed but i think it stops for like 2 ms because i checked and the walk speed didn't change. How can i change it so it doesen't stop and reach the player?
@@SuperFenix164 well that is how it should work. Just to make sure there is no other script running? Nothing like the ChaseAI module or anything ?
@@CritDEV i checked and nothing else is running
@@CritDEV oh sorry im just dumb i didn't know that it was touching me because i didn't setup the kill script
for some majestic reason if i try to call the SmartPathfind function then i get an error saying something along the lines of "SmartPathfind is not a valid member of module script "AI"" and it doesn't work at all. does anyone know why this is happening? I even tried copying the EXACT code in the video and i got the same issue
Make sure you did require(ai)
@@CritDEVi can't believe i forgot that. many thanks
@@CritDEVnevermind this time it still doesn't work, but there are no errors. and the path doesn't get visualized even when i set that value to true, does the API work with custom made characters or is it just for regular R6 and R15 roblox npcs?
@@fv2536 the error you originally got is unrelated to that. But as long as the entity has a humanoid and Motor6Ds it’ll work
@@CritDEV everything is unanchored, it has a humanoid, it has all the necessary Motor6Ds, it functions like an npc should. could there be any other reason why the api does not work? did it by any chance get broken recently due to roblox updates?
Is there any way to add a walking animation to the pathfinding AI?
That would be the standard way to edit animations in NPCs. I’m sure there are many tutorials out there
So I figured it out. So what you have to do is simply put the "Animate" script that you would find in the player or when you spawn a Rig via roblox and convert it into a server script.
my npc is not moving i dont know what to do
Is lagging when the NPC is too far, any way to fix this?
A recommendation would be not to use tracking when someone is far away
the script does not workkkk
what if you change it with a diffirent monster
@@ITssShawnVr it should work, just provide the correct StandardPathfindSettings if the size is different,
For details on what should be provided in that table, see Roblox’s “Character Pathfinding”
How do I make the balls invisible
EDIT: Nevermind just set visualize to FALSE
Is this good performance-wise?
Tracking is not. Otherwise, it is
it doesn't work
Is there a way to modify the speed of the agent?
Walkspeed of the humanoid
@@CritDEV I see, thx for the speedy reply.
I noticed it's not jumping either even though I have Auto Jump enabled on the humanoid? @@CritDEV
@@avidyoutubewatcher1897 In the settings there is a DefaultPathfindingSettings table, in that set AgentCanJump to true
how can you make it chase the nearest player?
Do a loop to get (playerpart - enemy part).magnitude for each one.
Store the current closest player and distance and at the end of the loop you’ll have your target.
You can also have a loop running in the background to detect if the closest player changed and call API.stop(enemy) and reset it.
it doesnt work for me
is it possible to use this for a tower defense
game
No that involves using nodes which is a different method of pathing NPCs
@@CritDEV ok thanks
is there a way to make it so if a player is a certain distance from the NPC that it stops what it's doing and goes after the player?
isnt possible with the api. try this tho!
local Forbidden = game.ReplicatedStorage.Forbidden
local AI = require(Forbidden.AI)
local function GetNearestPlayer()
local CurrentPlayer = nil
for _,v in pairs(game.Players:GetChildren()) do
if v:IsA("Player") then
if CurrentPlayer == nil then
CurrentPlayer = v.Character
else
if CurrentPlayer.HumanoidRootPart.Position.Magnitude < v.Character.HumanoidRootPart.Position.Magnitude then
CurrentPlayer = v.Character
end
end
end
wait(.025)
end
return CurrentPlayer
end
wait(1)
while wait(1) do
local Player = GetNearestPlayer()
wait(.5)
AI.SmartPathfind(script.Parent, Player, false, {Visualize = false, Tracking = false})
end
(put forbidden in replicatedStorage)
btw all this code is mine
except forbidden api :]
How can i set much more tracking location and to be in loop ?
please elaborate? What do you mean by much more tracking location and being in loop
@@CritDEV i fix all of that but how can i stop the NPC instantly
local rs = game:GetService("ReplicatedStorage")
local forbidden = rs:WaitForChild("Forbidden")
local ai = require(forbidden:WaitForChild("AI"))
local NPC = script.Parent
local function RandomLocation()
local locations = {
workspace.Points.Part1,
workspace.Points.Part2,
workspace.Points.Part3,
workspace.Points.Part4,
workspace.Points.Part5,
workspace.Points.Part6,
workspace.Points.Part7,
workspace.Points.Part8,
workspace.Points.Part9,
workspace.Points.Part10
}
return locations[math.random(1, #locations)]
end
local target = RandomLocation()
while true do
wait(0.1)
if script.Parent.Status.Walking.Value == true then
ai.SmartPathfind(NPC,target,true,{Visualize = true, Tracking = false})
target = RandomLocation()
else
print("NPC Stop walking")
ai.Stop(NPC)
end
end
Literally nothing works for me.
@@zombie_gamer2122 Please send a code sample.
StandardPathfindSettings, what is it.
When I download this the file is empty
please make sure you have gone to the link in the description.
I have checked, the file is there.
just tried on my game, rly badly calculates paths
Is Roblox’s pathfinding mechanism…
To enhance your results, use the StandardPathfindingSettings and other values to optimize your path, as well as the pathfinding blockers (object)
What would happen if there is no path available?
It wouldn’t run the pathfind.
It also returns this which can be used in your code! Enum.PathStatus.NoPath (only when yield = true
Give me a hour and I’ll push the update. Redownload the module at 5
Thank you!@@CritDEV
how do i make this go towards different waypoints and also damage the player
don’t know what you mean by go toward different waypoints but for the damage you just put a script inside the HRT and do
local db = false - stops script from running thousands of times a second
local damageCooldownTimer = 1 - seconds
HRT.Touched:Connect(function(hit)
local enemyChar = nil
if hit.Parent:FindFirstChild(“HumanoidRootPart) then enemyChar = hit.Parent end
if hit.Parent.Parent:FindFirstChild(“HumanoidRootPart) then enemyChar = hit.Parent.Parent end
if enemyChar == nil then return end
db = true
- damage code here
wait(damageCooldownTimer)
db = false
end)
@@CritDEV Thanks! and what i meant by different waypoints is like the ai patrolling to other points yknow like walking back n forth between points
There is a yield setting when you call the function.
Yielding is basically where it will stop further execution of the lines of code after the function call if true. Just make it so that it’s a loop and pathfinds between those locations after the previous pathfind finishes
how do I make my npc jump
I did everything right but it didn't work the dummy was unanchored aswell. Any help?:
local rs = game:GetService("ReplicatedStorage")
local forbidden = rs:WaitForChild("Forbidden")
local ai = require(forbidden:WaitForChild("AI"))
local NPC = script.Parent
local target = workspace.dest
wait(2)
ai.SmartPathfind(NPC,game.Players:GetChildren()[1],true,{Visualize = true, Tracking = true})
Is there an error code that printed
@@CritDEV I will check soon
550 subscriber❤
how to set max chase distance?
Range of pathfind in settings
AgentRadius?
I don’t understand it
Please tell me what confuses you so I can help.
@@CritDEV Om new to developing
how do i make the npc jum
I believe I have somewhere in the settings the default pathfinding settings, in there set AgentCanJump to true. If it isn’t jumping it could also be due to the humanoids jump power
Why doesn’t not work😢
@@THE_GOLDENSPECTRA please send a sample of your call so I can help you debug.
@@CritDEV ok
whyyyyy do I always need to download something suspicious??!?!?!?! Please just make a full tutorial instead of making everyone download some random model or plugin!
. . . You can go through the code on only the ai module and see. 🤷
Have you seen how much code these models and plugins have 😭
Also they are tools to make things way easier, veeeery grateful for it
didnt work,
@@JRAplayzstuffs Please provide information or join the discord
CritDev my comments keep disapearing for some reason on your reply so can you continue on here:
i changed it but it doesnt work I put a video on my channel showing the issue though
Can you send the call you used ?
Also for future reference in case you ever need it.
Making a video not made for kids does not mean 13+, 18+, etc...
it only allows for features like commenting and such and recommends videos for different audiences.
@@CritDEV oh my bad I didnt know. but heres the call its simple really: ai.SmartPathfind(troop, hit, true, {Visualize = true, tracking = true}) the troop being the npc, and hit being the part the mouse hit. and I tried playing around with changing SwapMovementMethodDistance in the settings table but nothings changing
@@chosenone3 in a day or so I will have tested and pushed a new version of the AI module, completely rewritten. I’m not going to rush it and I’m going to make sure it’s fully tested but it is “developed”
The issue is random problems which make pathfinding asynchronously the most annoying thing I’ve ever dealt with.
@@CritDEV alright I’m looking forward to it thank u good luck 🙏
you guys need it to chase you even after it respawns: here!
local rs = game:GetService("ReplicatedStorage")
local forbidden = rs:WaitForChild("Forbidden")
local ai = require(forbidden:WaitForChild("AI"))
local NPC = script.Parent
local targetPlayer = nil -- To keep track of the target player
-- Function to start AI pathfinding
local function StartPathfinding()
ai.SmartPathfind(NPC, targetPlayer, true, {Visualize = true, Tracking = true})
end
-- Function to stop AI pathfinding
local function StopPathfinding()
ai.Stop(NPC)
end
-- Function to handle player character added event
local function OnCharacterAdded(character)
-- Update target player to the newly added character's player
targetPlayer = game.Players:GetPlayerFromCharacter(character)
-- Start pathfinding
StartPathfinding()
end
-- Connect the player character added event
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(OnCharacterAdded)
end)
game.Players.PlayerRemoving:Connect(function(player)
if player == targetPlayer then
-- Player has left, stop pathfinding
StopPathfinding()
end
end)
-- Start initial pathfinding
StartPathfinding()
thank me later
Good script! Maybe consider making duplicate npcs to target different players
@@CritDEV i did and had some fun with it!
@@Lennypennyez Thanks man. I was able to modify that script and have it working as expected for me. (UPDATE 2)
local rs = game:GetService("ReplicatedStorage")
local forbidden = rs:WaitForChild("Forbidden")
local ai = require(forbidden:WaitForChild("AI"))
local NPC = script.Parent
local root = NPC.HumanoidRootPart
local targetPlayer = nil
local newtargetPlayer = nil
local db = false
local db1 = false
function FindNearestPlayer()
local minDistance = math.huge
local nearestPlayer = nil
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
local character = player.Character
if character and character:FindFirstChild("Humanoid") and character.Humanoid.Health > 0 then
local distance = (character.HumanoidRootPart.Position - root.Position).Magnitude
if distance < minDistance then
minDistance = distance
nearestPlayer = player
end
end
end
return nearestPlayer
end
function StartPathfinding()
while wait(1) do
if db then return end
db = true
local bot = NPC:FindFirstChild("Bot")
local botState = bot:GetState()
if botState == Enum.HumanoidStateType.Seated or botState == Enum.HumanoidStateType.Swimming then
task.wait(math.random(0.25, 1.5))
bot:ChangeState(Enum.HumanoidStateType.Jumping)
end
wait()
newtargetPlayer = FindNearestPlayer()
if newtargetPlayer and newtargetPlayer == targetPlayer then
if targetPlayer and targetPlayer.Character then
ai.SmartPathfind(NPC, targetPlayer.Character, false, {Visualize = false, Tracking = true})
end
end
wait()
if newtargetPlayer and newtargetPlayer ~= targetPlayer then
StopPathfinding()
targetPlayer = newtargetPlayer
if targetPlayer and targetPlayer.Character then
ai.SmartPathfind(NPC, targetPlayer.Character, false, {Visualize = false, Tracking = true})
end
end
--wait(5)
db = false
end
end
function StopPathfinding()
ai.Stop(NPC)
end
function OnPlayerRemoving(player)
if player == targetPlayer then
StopPathfinding()
end
end
function OnCharacterRemoving(character)
local player = game.Players:GetPlayerFromCharacter(character)
if player == targetPlayer then
StopPathfinding()
player.CharacterAdded:Connect(function(newCharacter)
OnCharacterAdded(newCharacter)
end)
end
end
function OnCharacterAdded(character)
targetPlayer = game.Players:GetPlayerFromCharacter(character)
if targetPlayer and targetPlayer.Character then
targetPlayer.Character:WaitForChild("Humanoid").Died:Connect(function()
OnCharacterRemoving(targetPlayer.Character)
end)
end
StartPathfinding()
end
function OnNPCSpawned()
if targetPlayer and targetPlayer.Character then
StartPathfinding()
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(OnCharacterAdded)
end)
game.Players.PlayerRemoving:Connect(OnPlayerRemoving)
NPC.ChildAdded:Connect(function(child)
if child:IsA("Humanoid") then
OnNPCSpawned()
end
end)
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
if player.Character then
targetPlayer = player
player.Character:WaitForChild("Humanoid").Died:Connect(function()
OnCharacterRemoving(player.Character)
end)
StartPathfinding()
end
player.CharacterAdded:Connect(OnCharacterAdded)
end
You're a life saver
bro is a lifesaver
doesnt work did all you did
Yeah I know, and I don’t know why cause I’ve looked through all the code over and over
@@CritDEV I'm pretty sure it's because the enemyroot is nil. I've done some prints on the AI ModuleScript and it just says the enemyroot = nil.
@Psygenz I’ll make it so that if enemyroot == nil then it ends the patthfind
It's most likely because the Humanoid name is not "Humanoid"
@@CritDEV 👍
epic
I have a pathfinding bug when handling with multiple enemies with one script. I am currently finding a fix at the moment. If you have any ideas or suggestions let me know. Here’s a video th-cam.com/video/ec6feocxMhA/w-d-xo.html
Update: I have found a general fix for this. While looping through the waypoints, I am skipping the first 5 waypoints to prevent the enemy from jittering
your not even explaining. your confusing me so much.
@@NotFakerMiddle Most people understand. If you are new to coding you may not.
@@CritDEV no, I understand coding, I just didn’t understand where to put the scripts, you said to put it in replicated storage, but what about the NPC?
@@NotFakerMiddle You create a script as shown in the video. For more, you can join the discord in the video description.
Yay I can make a horror game