Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Whats the best way to make a npc follower?

Asked by 5 years ago

Im trying to make an npc that will just walk behind the player and follow them around. I tried using pathfinding to do this but it seems to be really janky and chopy. Heres the code for it :

01--Services
02local PathFindingService = game:GetService("PathfindingService")
03 
04--Variables
05local targetCharacter = script.Parent.Parent.Parent
06local target = targetCharacter:WaitForChild("HumanoidRootPart")
07local localCharacter = script.Parent.Parent
08local localHumanoid = localCharacter:WaitForChild("Humanoid")
09local localRoot = localCharacter:WaitForChild("HumanoidRootPart")
10 
11--Functions
12function moveTo()
13    print("Moving to player")
14    local pos = target.Position + target.CFrame.LookVector * -2 + target.CFrame.RightVector * 2
15    localHumanoid:MoveTo(pos)
View all 65 lines...

If some one could fix the code to make the movement smoother or just tell me a better way I would apreaciate it alot :)

https://gyazo.com/3e0e075f6b6d6f740ba2e5d302e55b8a

0
Instead of doing while true do, use RenderStepped, because that will run everytime a new frame is generated. I think this would make the movements and turning smoother? But, I'm not sure. I don't really work with AI or PathFindingService. Fires every frame prior to the frame being rendered. https://developer.roblox.com/en-us/api-reference/event/RunService/RenderStepped killerbrenden 1537 — 5y
0
game:GetService("RunService"):Connect(function() print("Running Main") main() end) killerbrenden 1537 — 5y

Answer this question