I have an NPC whose job is to track down the player once they are within its range. Everything works fine enough, but there’s an issue that’s causing me to tear my hair out trying to figure out a solution.
Below is a video of the NPC in action.
If you pay attention, you’ll notice the NPC, as oppose to smoothly moving from point A to point B, teleports around towards its final destination. This bugs me mainly because of visual appeal, or lack thereof, when the NPC does this.
I have attempted to search through solutions, but all of them are either regarding :MoveTo() (which doesn’t work for me for some reason) or aren’t smooth for a reason that doesn’t apply to me.
I don’t know why it’s doing this and I’m genuinely stuck.
I’ve provided the important part of the code below, which is placed within a loop that runs every RunService.Stepped (I apologize for the messy code):
if detectiontick > 50 then
if detectiontick == 70 then
script.Parent.Parent.Parent.Humanoid.Animator:LoadAnimation(script.Run):Play()
script.Parent.Parent.Parent.Humanoid.WalkSpeed = 22
game.ReplicatedStorage.NPC.Tools.StunGunVisual:Clone().Parent = script.Parent.Parent.Parent
end
task.delay(0.1, function()
if script.Detecting.Value ~= nil then
script.Parent.Parent.Parent.HumanoidRootPart.CFrame = script.Parent.Parent.Parent.HumanoidRootPart.CFrame:Lerp(CFrame.lookAt(script.Parent.Parent.Parent.HumanoidRootPart.Position, Vector3.new(target.Position.X, script.Parent.Parent.Parent.HumanoidRootPart.Position.Y, target.Position.Z)), 0.25)
end
end)
if detectiontick/50 == math.round(detectiontick/50) then
dist = 20
script.Parent.Parent.Parent.Humanoid.AutoRotate = false
script.Parent.Parent.Parent.Humanoid:Move((target.Position - script.Parent.Parent.Position))
end
end
Help would be greatly appreciated.