Advanced Roblox Scripting Tutorial #21 - Pathfinding (Beginner to Pro 2019)
Вставка
- Опубліковано 1 чер 2024
- Advanced Roblox Scripting Tutorial #21 - Pathfinding (Beginner to Pro 2019)
Hey guys! Welcome back to a brand new roblox scripting tutorial. In today's video I am going to be teaching you about pathfinding / pathfinding service. This is an insanely fun but important topic and I'm so excited to show you guys! If you have any questions like always leave them in the comments. Enjoy :)
Character Loading Plugin: www.roblox.com/library/752585...
-- Follow me on twitter! (my name is tapwater because thats my main channel): / realtapwater
-- Follow me on Instagram! (my name is tapwater because of my main channel): / realtapwater
- Join my Discord Server to learn and meet other developers!-
/ discord
Link to Beginner's Tutorial Series:
• Beginner's Roblox Scri...
--What is this series about and who is it for?
So this series is meant for people who really want to learn exactly how to script, if that is you then I promise by the time you watch this whole series you will know exactly how to script on roblox. Anyways be sure to subscribe to see whenever I release a new tutorial and I will see you guys in the next one. Peace!
Hey guys! I'm planning on uploading a lot more and I'm really excited for the future of this channel. Be sure to join the discord server to stay connected, meet other devs, and learn!: discord.gg/FKcSyRh
I'd love a tutorial on Mesh Deformation it'll be kind of complicated though.
I like ur vids
thanks :)
once the NPC has reached one part, how do I make him move to another part and then loop that so he keeps walking like that?
Can I make a game with u
7:20 "It's gonna get stuck on the wall - cuz it has *no brain* "
Poor NPC ;c
Lol
The funny thing is that he is calling HIMSELF a "no brain"
@@snoanashi1597 lol
20:25 Have captions on lmao
"stripping tutorial... im serious im gonna do some sex criminals"
lmao
20:47 “laying it in my own baby”
@@cooperknows5627 lol
and then it said after the s*x criminal it said sick scripting LOL
Hey @TheDevKing, I really appreciate your scripting tutorials from the past (lol). Before I watched your scripting tutorial for pathfinding, I would be confused because I was quite a new scripter back then. After watching your video, understanding it, and practicing it, I can now make a randomizer for this specific service! Thanks a lot! Hope you make more tutorials like this!
2:25 We're going to use r15 cause it's pretty simple. *deletes r15 model*
guess not
I think he meant r6
@@robuxgod926 ye same
i noticed that too!
LoL yeah
i love how when he doesnt know what to say about something he just acts like he never talked about it and just says "you know what i mean anyways"
Perfect i needed this for fire flies thank you so much perfect timing coming in clutch every time
Awesome good luck with the flier flies lol
@@TheDevKing it's really hard and i have the script and everything right and its not working i think ima restart lol i'ma keep working on my scripting
@@TheSxrged absolute lad
any1 who thinks hes a mind reading lizard? Anyone?
@@chickenoodle3397 you making a one piece game?
I love your videos, they're funny and useful
Thanks for all your vids man.
Yooooo. I needed this. Tysm
:)
Why not works in my world? :(
@@AlguienPromedio For me it said "Infinite yield possible" in the line where i defined the torso. That's because in the later version there is no part called a torso there is either upper torso or lower torso. Hope I helped.
i finally made an working spins system after 1 week of tutorials on google and youtube, I wouldn't be able to make this if it wasn't for alot of people including you so... THANKS ALOT
mostly you xD
Amazing 👏👏👏👏👏
Keep up The good work! 😀 😀 😀
Tysm this was a useful tutorial!
the reason it is "lagging" is because of the wait(2). towards the end the paths were shorter because the npc just had to jump over stuff, so it was taking less than 2 seconds to get to the next waypoint and it had to stop and wait for the 2 seconds to finish.
Instead you should make it wait until the movetofinished is called
how lol
just remove the number inside the wait()
@@ImJustNeon Yeah but think about the lag afterwards, because standart its 0,3s
i think task.wait() is way better
@@IcikiwirJava task.wait wouldn't work in this case, because what the wait function for the npc is specifically used to wait for until the npc hits the waypoint. That means that it could end up waiting for eternity if it never touches the waypoint, but if it does touch the waypoint, it will stop waiting, and the loop will continue to the next waypoint. Task.wait on the other hand, just waits a set amount of time, whether the npc hits the waypoint or not.
Thank you so much, i've been scripting for a while(6 months-ish) and this helped me alot I cannot thank you enough for this
This is the clearest tutorial on this I have found! This stuff is great!!! If this doesnt earn a sub from everyone idk what does
Thank you, this helped a lot!
good video!
omg, okeanskiy. I've seen your videos man! Thanks a lot. Keep up the great work as well! :)
Its almost as if you made it...
@@TheDevKingHello
@@TheDevKing really said omg and hes verified lol (no hate)
THANKKK YOU MAN I FINALLY KNOW HOW TO USE PATHFINDING!!!
hey thanks so much! i figured out how to make my character go back and forth between two parts!
20:30 this is the story of sent_cons
Lol
oop
open the captions
Lfmao
XDDDDDDD
For all of you confused , 1) You have to type local torso = script.Parent:WaitForChild("UpperTorso") for r15 2) if your rig is still not moving, make sure the humanoid root part isn't anchored
Thank you
Thank you so much for help!
alternatively set the torso variable to humanoidrootpart
@@GalaxinTM you could, but for the script in the video i suggest following what i said
If you are doing it with an R15 character, replace the torso with the "HumanoidRootPart"
i like ur tutorials alot bcs u explain everything step-by-step
when you do this on a r15 rig, make sure that you have the HumanoidRootPart unanchored otherwise the character won't move.
Thanks bro
If you want to have the path constantly update and overcome newly placed obstacles which weren't calculated by the previous path, recalculate the path in a while loop until the character reaches the finish position!
how does one do this? ive been trying to do it
how does one do this? ive been trying to do it
Thank you dude!
+ subscriber
at the very end, you can use task.wait(2s) and then part:Destroy(), so that way it won't make too much parts on ur workspace
Fun thing to do: Make lots of them with the pathfinding script. Put the endingpart inside the region3 from the tutorial a bit back. Where when found inside they die :)
Awesome!
If you want the npc to go to one point then to another all you have to do is after finishing the script go down 1 and write wait(1) then copy and paste the first part under the wait(1) and change ending part to the name of the other part
Thanks you're a life saver! :D
could u explain a bit further? like what parts exactly do I change and keep and paste. Thanks
nvm I managed to do it on my own, I just did this after the main script:
wait()
human.MoveToFinished:Wait()
human:MoveTo(game.Workspace.Goal2.Position)
if anyone wants me to paste my whole script then just ask (I didnt add the zombie stuff)
@@liamrileyborreshi can you paste it even though it's been a month
If u guys are making an npc that shoots u but stays further away, well what u gotta do when the npc s searching for the player, turn the pathfinding on, the when npc is close enough, turn it off. Simple!
im also improving my english watching your tutorials and not just scripting skills!
to avoid it getting stuck you can just keep generation a waypoint and move to index 1 everytime
What? I don't know what you are saying?
You should just make it generate a waypoint only every time it gets stuck because if you keep generating waypoints constantly, it will take up server ram and cause lag which isn't good for optimization, Great Idea though!
Thanks for the amazing tutorial! I’m using it for a game similar to Work at a Pizza Place. I needed pathfinding so I could spawn NPCs at random locations. They needed to walk to the cashier to take their orders lol.
nice :D
Thanks :D
@@Nathanator how's the game going?
@@YorktownClass I ended up quitting Roblox development due to being busy with school and other things, I'm working on becoming an app developer instead now.
@@NathanatorWell i wish u good luck on achieving that! but can you tell me what's the *real* reason you stopped? (i'm making a game and if you can give me a headsup can really do me favor) btw i bet you forgot about this comment looll
Just spending a few hours on roblox devhub repeating the basic coding lessons and then coming here its easier to understand what a part of code does and not directly copy paste something someone made not knowing what it does.
Now I know how to make AI's for my enemies in my games u are a legend
So with this method, which matches what's on the wiki for pathfinding, the pathing NPC will start to momentarily pause at each point along the path. You can see this start at 19:22. Any idea how to correct this?
Basically in the script at the first put: script.Parent:SetNetworkOwner(nil)
I just turned my local stop sign into a humanoid and its chasing me, help me
Amazing! You are genius!
Wow u good
xDDD
why
@@littletimmy9902 y not
this is extremely helpfull
SOOO SWAGGG
Hello, everyone! if you are too lazy to type the script, here is the fully written sc:
local PathFindingService = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local path = PathFindingService:CreatePath()
path:ComputeAsync(torso.Position, game.Workspace.EndingPart.Position)
local Waypoints = path:GetWaypoints()
path.Blocked:Connect(function()
end)
for i, Waypoint in pairs(Waypoints) do
local part = Instance.new("Part",workspace)
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = Waypoint.Position + Vector3.new(0, 2, 0)
part.Anchored = true
part.CanCollide = false
if Waypoint.Action == Enum.PathWaypointAction.Jump then
human.Jump = true
end
human:MoveTo(Waypoint.Position)
human.MoveToFinished:Wait()
end
human:MoveTo(game.Workspace.EndingPart.Position)
I used this and it just created neon ball parts. not moving the character or anything
Edit: It was a different character type. now its fixed
YOU ARE A LIFE SAVER
YOU DESERVE A LIKE
i just saved myself later on wow
im lazy, thanks
You know, this would make a great game idea, you have to get the bot or AI to the finish line, and you have to help it get there.
This concept has been used, it is really cool. Good thinking.
Make it!
soronorjspro show us
@@migriv4603 Perhaps I will make it... perhaps.
@@maxbuilder6801 yes make it best idea ever! I'm gonna make it but not publish
I took a break for a long time from this series and after this ill be going to new territory! "I was just reviewing to refine my skills"
Bro thank youuuuuu😁😁😁
do not go to 20:29 and turn on subtitles!! worst mistake of my life 😭
Uh oh
Thedevking promised us sex scripting tutorials!! He lied 😡
Can you make a tutorial on a autopilot car where you can select the location where it’s gonna go and turn it of if you want?
Isnt this video showing how?
i made it, made a cool path and for some reason it flies over the parts, lol. i know this is still kinda like an "alpha" pathfinding service but ye, nice vid
If you use R15, this won't work exactly the same, use an R6 model because it has "Torso" and not "Upper" or "Lower Torso." I haven't gotten the r15 to work but I assume you can target both upper and lower torso at the same time to be able to move it. Or perhaps it's humanoidrootpart, but I haven't figured it out.
Messaging Service noww hehe, trying to make a global matchmaking system hehe so would definitely appreciate a helpful video 😀
Coming soon :)
@@TheDevKing 🙏🙏🙏
alvinblox made a video on messaging service - ua-cam.com/video/uI6MIZ3Y7ZY/v-deo.html
alvinblox is also a good roblox scripting youtuber
@@LArk25 for beginners. this is the advanced series
@@DanielP533Scripts that tutorial is still helpful...
20:00 instant karma XD
xD
I remember watching your videos.
I’m gonna make it go after the player thanks!
what about when it plots a course through a small gap that it cant fit through? i suppose that falls under the blocked category?
Then the humanoid jumps
Hey man, i checked this tutorial out just to learn pathfinding and its super helpfull. I already made my own pathfinding function through a whole map and everything but when i move around the mob it sometimes just gets confused and stops moving. Is there maybe a solution for this?
send a code, we'll help you troubleshoot
@@alive4269 a year late
what@@dopxy9219
do you still need help
The most important thing I learnt is NEVER EVER CHALLENGE AIs OR AI BOTS.
PS most funniest video by mat--no the devking
im gonna use this in my albion online ripoff lol thanks!
script for lazy people like me:
local PathfindingService = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local path = PathfindingService:CreatePath()
path:ComputeAsync(torso.Position, game.Workspace.endingpart.Position)
local waypoints = path:GetWaypoints()
for i, waypoint in pairs (waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait(2)
end
Your welcome
thanks
@betagam4523p any way to make it control a car to go to a location then? ive been trying to find how to do it without neural networks, but ive had no luck. i kinda need help with this, thanks. What im trying to do is to make an ai police car basically, like in need for speed rivals, that are suprisingly blood thirsty to destroy your car
Thanks a lot, i was very lazy to do this thing.
thanks bro
@betagam4523p I'm working on a taxi whit the script. Thank you so much!
Hey DevKing do you think we could teach the AI to climb and swim?
Edit: oh wait nvm you can!
Edit 2: ok so the AI can’t actually calculate them being able to climb so it disables there ability to jump, maybe we could fix thris
THE ULTIMATE SPEED RUNNER
For me, the script worked and everything was fine, but when I put a more complicated one with more jumping, it doesn't work. What could cause such an issue?
Update: It is not reading the for loop. Does anyone know why?
What if I want to have two checkpoints and I want the NPC to walk in a loop without stopping?
yeah thats a problem XD
@@WaW_Real no its not its really easy :/
could you make a tutorial about making learning ai from hello neighbor the stealth horror game. so that the bot learns and sets up traps and blocks doors the more times you go into a certain area
that sounds way too advanced to be explained in one video
Bro, even piggy doesn't have that.
Roblox pathfinding is not that advanced
2030 have that
idk why everyone is acting like it's making the ai become sentient, you can just check if the player went in a certain area and then make the ai set up more traps. Hello neighbor AI isnt that good
thanks!!
Great video but at 13:39 why didn't you just type humanoid.Jump = true. Instead of all that other stuff? Also, you didn't get rid of the strait moveto
Does it work the same I have never tried it but I will try it if it works.
Roblox did some updates, and I fixed the script, because in the new version the AI will infinitely double-jump. (This is for R15)
local pathfinding = game:GetService("PathfindingService")
local hum=script.Parent:WaitForChild("Humanoid")
local rootPart=script.Parent.HumanoidRootPart
local path=pathfinding:CreatePath()
path:ComputeAsync(rootPart.Position,game.Workspace.Target.Position)
local waypoints=path:GetWaypoints()
for i, waypoint in pairs(waypoints) do
if waypoint.Action==Enum.PathWaypointAction.Jump then
if not(hum:GetState()==Enum.HumanoidStateType.Freefall) then
hum:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
hum:MoveTo(waypoint.Position)
hum.MoveToFinished:Wait()
end
Thank you, been trying to figure out what was wrong with my code ♡☆
It looks a lot more complicated with dark mode on
how do you make the npc follow a specific guy. Like think I have a player with a value called "Notplayer" inside of the player. And there is a player who does not have the value. And I want it so that I want the guy with the value be followed by the npc. How do you do that?Can you make a separate video of that pls pls?
I need some help like when I put the script It doesn't move altho I removed the wander bc It always wander away from the path Is there anything Im doing wrong?
If you want to you can add more parts to make like a smooth line like this:
local PathFindingService = game:GetService("PathfindingService")
local Human = script.Parent:WaitForChild("Humanoid")
local Torso = script.Parent:WaitForChild("Torso")
local path = PathFindingService:CreatePath()
path:ComputeAsync(Torso.Position, workspace.endingPart1.Position)
local waypoints = path:GetWaypoints()
for i, waypoints in pairs(waypoints) do
Human:MoveTo(waypoints.Position)
Human.MoveToFinished:Wait(2)
end
local path = PathFindingService:CreatePath()
path:ComputeAsync(Torso.Position, workspace.endingPart2.Position)
local waypoints = path:GetWaypoints()
for i, waypoints in pairs(waypoints) do
Human:MoveTo(waypoints.Position)
Human.MoveToFinished:Wait(2)
end
how do i make it so that the NPCs don't walk into the walls while trying to get to waypoints
@@KyleBunnyBunsYTube Keyboard
is it possible for the NPC to pathfind a player instead of a brick?
You could add a simple player finder as well, so have it say patrol with the brick system then it will break off when it sees a player and then it would go back to patrolling when player is dealt with or far away
im using this for Movement in my FNAF styled game Thank you
@@dizzy7466 idk
you can turn on nav mesh to see where he can stand on and where not
How do you make a new path if the old one gets blocked?
you probably do path:ComputeAsync() again (but i havent tried it)
If anyone want's to make it so that it creates a new waypoint to follow when you move the end part then copy this script:
local PathFindingService = game:GetService("PathfindingService")
local hum = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
-- A little feature that I added to put the spheres inside a folder to make it less messy in the workspace
local PathSpheres = Instance.new("Folder")
PathSpheres.Name = ("Paths")
PathSpheres.Parent = game.Workspace
local path = PathFindingService:CreatePath()
path:ComputeAsync(torso.Position, game.Workspace.EndingPart.Position)
local Waypoints = path:GetWaypoints()
path.Blocked:Connect(function()
end)
for i, Waypoint in pairs(Waypoints) do
local part = Instance.new("Part",game.Workspace.Paths)
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = Waypoint.Position + Vector3.new(0, 2, 0)
part.Anchored = true
part.CanCollide = false
if Waypoint.Action == Enum.PathWaypointAction.Jump then
hum:ChangeState(Enum.HumanoidStateType.Jumping)
end
hum:MoveTo(Waypoint.Position)
hum.MoveToFinished:Wait()
end
while wait(0.15) do
local part = Instance.new("Part",game.Workspace.Paths)
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = torso.Position - Vector3.new(0, 1, 0)
part.Anchored = true
part.CanCollide = false
hum:MoveTo(game.Workspace.EndingPart.Position)
end
thank you you are a life saver
Remember to set the ending position block to be no collide! Solved it for me
Would a pathfinding script work on something like a grenade? For example could I script the grenade to track down other players?
What about making a part go to another part using pathfinding?
make the npc invisible and attach your part to it
@@ausbossmoved or just tween along the waypoints like you'd normally do
if your npc is not working
try to delete a humanoid in the workspace, that fixed it for me
How did you select the rams like that without morning your cursor to explorer??
Im a little late to the party but how would i make the npc move towards a player?
watch the next video
make that the ending part is FindfirstChild:("HumanoidRootPart")
Ight thx dude
@@isaiahbenjamins8818 btw u have to get the position of the thing not just the block
ye ight thx
POV: ur watching this in 2022 cuz you don’t know how to code yet
pov: you know how to code and know all the basics and most advanced things but you just need to know how to code an ai
Lol
I'm in 2022 cuz I'm learning how to code
@@floof6896 tru
The Jokes on You,I forgot everything aside from the very basics of the syntax and redoing the advanced series again
Hey!
Would it be possible to weld the end part to a startercharacter and have it follow you forever?
or make it detect a player in the area and follow the root part of the player
@@per_cept yes you would use magnitude
"weld" would work just bad, use "weld constraint"
Update: you no longer need a plugin to insert your own avatar, I know this video wasn't young enough to notice but you now can use the built-in "Rig Inserter" to insert your own avatar, How? Besides Block, Mesh, Slender, and RThro there is a "Your avatar button".
Apply Auto-Subtitles here (20:24). What a slip up, DevKing; RIP my innocent brain.
Those darn Criminals tainting my Lua education..
Lol
If any of you want the NPC to go to the object that moved WITHOUT slowdowns then I was able to make a script below:
~~~
local pathfindingService = game:GetService("PathfindingService")
local target = game.Workspace.Finish
local targetPosition = game.Workspace.Finish.Position
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
while true do
wait()
local path = pathfindingService:CreatePath()
path:ComputeAsync(torso.Position, game.Workspace.Finish.Position)
local waypoints = path:GetWaypoints()
for i, waypoint in pairs(waypoints) do
if target.Position == targetPosition then
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:wait()
else
targetPosition = target.Position
break
end
end
end
~~~
*The script above is RIG 3rd script, the stuff below will tell you about the other Rigs*
I made a script which moved the object every 5-10 seconds and after moving the RIG3 ( I had 3 different rigs) moved to the object immediately
Rig 1 was the one The Dev King did but with the while true loop, but the problem is that he was going to the position if after the object was moved so only after he reached position he would go to a new one:
~~~
local pathfindingService = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
while true do
wait()
local path = pathfindingService:CreatePath()
path:ComputeAsync(torso.Position, game.Workspace.Finish.Position)
local waypoints = path:GetWaypoints()
for i, waypoint in pairs(waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait()
end
end
~~~
Rig2 on the other hand moved immediately after the object moved but the problem is that he was stuttering every step he took, meaning he would take a step and freeze for a sec, and the other problem is that he couldn't jump at all:
~~~
local pathfindingService = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
while true do
local path = pathfindingService:CreatePath()
path:ComputeAsync(torso.Position, game.Workspace.Finish.Position)
local waypoints = path:GetWaypoints()
local waypoint = waypoints[2]
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:wait()
end
~~~
And after using the mistakes from 2 rigs I was able to improve my pathfinding
This needs more likes
W
W tutorial
Best tutorial ever! But the NPC can double jump, even while falling, does anyone know why?
Every tutorial I watch nothing works and I'm getting sick of it. I've already smashed two keys in because of it
On line 11 , the word waypoint , on my computer it says it's errored . So I tried putting a s at the end of it like the blue thing that pops up suggested . Neither worked . Am I missing something ? I double checked also
@@robingibson5445 if your bullet is not firing make sure it is not on the ground
I kinda wish I had waited for this video...
lol uhh well now its here! :)
WORKS!!!
i put a part
be proud of me
POV: ur watching this in 2023 because u don't know how to code yet
tap water
ㄚ 乇 丂
12:00 marking my spot for now
For r15 there is no torso there is upper torso or lower torso because of that I use the HumanoidRootPart witch every character has
You are welcome.
local PathfindingService = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local path = PFS:CreatePath()
p:ComputeAsync(t.Position, game.Workspace.endingPart.Position)
local waypoints = p:GetWaypoints()
for i, waypoint in pairs(waypoints) do
local ball = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position + Vector3.new(0,2,0)
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait(2)
end
human:MoveTo(game.Workspace.endingPart.Position)
literally full of errors
stappp I wanna learn
Here's the code if anyone wants all the waypoints to show before he starts moving, with colour changing waypoints when he gets to that waypoint:
local Pathfind = game:GetService("PathfindingService")
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Torso = script.Parent:WaitForChild("Torso")
local Path = Pathfind:CreatePath()
local Target = workspace.Target
local GenPoint = nil
local PointArray = {}
local Folder = Instance.new("Folder")
Folder.Name = "Waypoints"
Folder.Parent = workspace
Path:ComputeAsync(Torso.Position, Target.Position)
local Waypoints = Path:GetWaypoints()
for i, v in ipairs(Waypoints) do
GenPoint = v
print(GenPoint)
table.insert(PointArray, GenPoint)
local Point = Instance.new("Part")
Point.Anchored = true
Point.Shape = "Ball"
Point.Size = Vector3.one*0.5
Point.Position = v.Position + Vector3.new(0,2,0)
Point.CanCollide = false
Point.Parent = workspace.Waypoints
Point.Name = "Point"..tostring(i)
end
for i2, v2 in ipairs(PointArray) do
if v2.Action == Enum.PathWaypointAction.Jump then
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
Humanoid:MoveTo(v2.Position)
Humanoid.MoveToFinished:Wait()
workspace.Waypoints["Point"..tostring(i2)].BrickColor = BrickColor.new("Camo")
workspace.Waypoints["Point"..tostring(i2)].Material = "Neon"
end
THANK YOU I NEEDED THIS
the "smart" zombie does not go all the way round. The goes around the first wall then decides that he can't be bothered to walk around the second wall. He walkeds into it and stops.
literally every single tutorial i watched doesn't even do anythng to make it so that the NPC doesn't walk straight into walls.
i'm having the same issues too..!
i tried this, but something unusual happened, they seemed to be hellbent on bunching up at a certain point on the map that was odd, before moving on to the goal... i don't know how to fix this...
Here is the script for you all to copy and paste :D
endingPart = game.Workspace.endingPart --change this to where it is in the workspace
while true do
local PathfindingService = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local path = PathfindingService:CreatePath()
path:ComputeAsync(torso.Position, endingPart.Position)
local waypoints = path:GetWaypoints()
for i, waypoint in pairs (waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait(2)
end
human:MoveTo(endingPart.Position)--change here
end
while true do
local PathfindingService = game:GetService("PathfindingService")
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")
local path = PathfindingService:CreatePath()
path:ComputeAsync(torso.Position, endingPart.Position) --change the endingPart to the part you want it to walk to
local waypoints = path:GetWaypoints()
for i, waypoint in pairs (waypoints) do
if waypoint.Action == Enum.PathWaypointAction.Jump then
human:ChangeState(Enum.HumanoidStateType.Jumping)
end
human:MoveTo(waypoint.Position)
human.MoveToFinished:Wait(2)
end
human:MoveTo(endingPart.Position)--change here
end
what do u mean by --change this to where it is in the workspace
@@teamcatyt4503 change it to the name of the part
@@JoshuaDZ its a model. The script i am putting is in the npc. I insert the name of it and next the pos?
@@teamcatyt4503 You should watch the beginner's series and work your way up. This script should be easy to comprehend.If you want the destination to be a model, then set the primary part of that model and set it there. This is why you watch the video to learn and not just copy/paste from description
Stop making people lazy