Is there a way to make npc's walk smoothly?

Hello,

So i’m working with npc’s right now but i’m running into a problem which is that the npc isn’t walking smoothly. So I wondered if there is a way to make them move smoothly.


local pfs = game:GetService("PathfindingService")

local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("HumanoidRootPart")

local path = pfs:CreatePath()
path:ComputeAsync(torso.Position, game.Workspace.AIParts.HouseSet.Destination.PrimaryPart.Position)

local waypoints
waypoints = path:GetWaypoints()

for i, waypoint in pairs(waypoints) do
	human:MoveTo(waypoint.Position)
	human.MoveToFinished:Wait(2)
end

human:MoveTo(game.Workspace.AIParts.HouseSet.Destination.PrimaryPart.Position)

You would probably have to animate that yourself.

Yes i know but I mean for when they turn.

Try Tweening the Torso’s rotation so that it turns smoothly.

for i,v in ipairs(npc:GetDescendants()) do
if v:IsA("BasePart") then 
v:SetNetworkOwner(nil)
end
end

SetNetworkOwner(nil) will make it so no player can have network ownership of the instance which will stop it from being “unsmooth” when two players constantly walk near an npc causing it to warp and visually teleport.

2 Likes

You are using :Wait(2) which means it will only check for MoveToFinished every 2 seconds which is probably your problem. Changing this to :Wait() should fix that.

It doesn’t fix the problem. @BillPlayzToday

There are no player’s in the server.

Show a visual gif/video of your problem so I can better understand what isn’t “smooth”

Pretty sure it does. What is really the problem here can you send us a video or a gif just like @Velliaan said?

I know I don’t have an animation yet but that doesn’t solve the problem when the npc rotates aournd the wall.

What? I’m confused. In the video you’ve sent it’s working as you’ve intended. What are you trying to achieve? If you want it to move robotically you should have pre-placed nodepoints

Just smoothly like we walk around corners. @tVellian

Or isn’t there a way to make them walkl smoothly around the corners?

As i mentioned in previous post if you want them to move “elegantly” you should have preset node points or mess around with the new path finding features to make the npc always walk central or not directly next to the wall, i can’t provide more help because you aren’t giving me a visual representation of what you want to achieve, the gif shown works as intended

Like what information do you need?

As you can see in the vid the npc doesn’t rotates smoothly around the wall. Which I need for my project which is a movie. Now I used animations for the walk but that doesn’t fix it it only makes the npc look like its walking which it is…

In that case, you shouldn’t use pathfinding service. Just make your own waypoints.
Unless there’s a way to make the navmesh more smooth, that is.

And then curve the waypoints so it is smoothly?

One way could be to use Bézier Curves.

Totally forgot about them I actually used them before in one of my other projects 2 years ago.

You can either do that, or just place them manually as parts.