CFrame based NPC walking going crazy

Try this:

for i, v in ipairs(path:GetWaypoints()) do
	--Distance to goal
	local dist = (restockerNPCHum.RootPart.Position - v.Position).Magnitude
	dist = dist - restockerNPCSize.Z/2 --Dist minus thickness of character

	local calculatedTime = (dist/restockerNPCHum.WalkSpeed)
	local currPos = restockerNPC:GetPivot().Position
	local goalPos = v.Position
	--Vector Direction looking toward our goal position from current pos (ignoring Y axis)
	local lookVector = CFrame.lookAt(currPos, v.Position).LookVector *,0,1) 
	--Position 10 units forward of goal position relative to character lookVector
	local lookAt = v.Position + (lookVector * -10)
	--Final CFrame to tween to
	local calculatedCFrame = CFrame.lookAt(v.Position, lookAt)
	local tween = tweenService:Create(restockerNPCHum.RootPart,, Enum.EasingStyle.Linear), {CFrame = calculatedCFrame})
1 Like


I have no idea how your getting those values.

Me neither, I am beyond confused. I’ll be opting for lerping instead.

That’s origin Position not current position

When I press F on it, It takes me to this void. Even if I don’t zoom in on it, I don’t see the NPC it’s just… Gone!

Change this part to:

local currPos = restockerNPCHum.RootPart.Position
1 Like

The NPC got poofed, Apparently you can’t tween humanoids using CFrame (position + angle).

Sure you can. There is something else happening.

I’m gonna try CFrame:ToWorldSpace()

local calculatedCFrame =

Whooooops! I did something wrong here.

Aw man… It still gets sent to an alternate timeline!

try commenting out the tween:Play and wait lines totally then run your code. See what happens.

There’s something wrong with the calculations…

1 Like

Did you run the code with the tween lines commented out?

Yeah, I replaced it with root.CFrame = calculatedCFrame

no don’t replace it. We need to see if there is something else effecting the movement. So we want that loop to not do anything at all.

I replaced it after i ran it with the tween lines commented out. And there was nothing affecting the movement.

So it only goes to crazy when the tween runs? If the tween doesn’t run, then the character stays at the start position?