NPC’s are not like players, you move them using scripts so you can easily move them on the axis, here is a simple function that can help you do that:
function MoveToDirection(npc:Model,direction:Vector3)
local Humanoid = npc:FindFirstChild("Humanoid")
local HumanoidRootPart = npc:FindFirstChild("HumanoidRootPart")
if Humanoid and HumanoidRootPart then
local lx = math.abs(direction.X)
local ly = math.abs(direction.Y)
local lz = math.abs(direction.Z)
local distination
if (lx > ly and lx > lz) then
distination = HumanoidRootPart.CFrame.Position + Vector3.new(direction.X, 0, 0);
elseif (ly > lx and ly > lz) then
distination = HumanoidRootPart.CFrame.Position + Vector3.new(0, direction.Y, 0);
else
distination = HumanoidRootPart.CFrame.Position + Vector3.new(0, 0, direction.Z);
end
Humanoid:MoveTo(distination)
return Humanoid.MoveToFinished
end
end
--We can now move the npc to any direction using this function like this:
local NPC = game.Workspace.Rig
--To make the NPC move left 15 std.
local leftDirection = Vector3.new(15,0,0)
MoveToDirection(NPC,leftDirection):Wait()
--To make the NPC move forward 50 std.
local forwardDirection = Vector3.new(0,0,50)
MoveToDirection(NPC,leftDirection):Wait()
--To make the NPC move right 20 std.
local rightDirection = Vector3.new(-20,0,0)
MoveToDirection(NPC,leftDirection):Wait()
--To make the NPC move backward 70 std.
local backwardDirection = Vector3.new(0,0,-70)
MoveToDirection(NPC,leftDirection):Wait()
again, if you don’t want the NPC to turn smoothly you can use this function instead:
function MoveToDirection(npc:Model,direction:Vector3)
local Humanoid = npc:FindFirstChild("Humanoid")
local HumanoidRootPart = npc:FindFirstChild("HumanoidRootPart")
if Humanoid and HumanoidRootPart then
local lx = math.abs(direction.X)
local ly = math.abs(direction.Y)
local lz = math.abs(direction.Z)
local distination
if (lx > ly and lx > lz) then
distination = HumanoidRootPart.CFrame.Position + Vector3.new(direction.X, 0, 0);
elseif (ly > lx and ly > lz) then
distination = HumanoidRootPart.CFrame.Position + Vector3.new(0, direction.Y, 0);
else
distination = HumanoidRootPart.CFrame.Position + Vector3.new(0, 0, direction.Z);
end
if direction.X > .1 then
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.p, distination)
elseif direction.X < -.1 then
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.p, distination)
elseif direction.Z > .1 then
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.p, distination)
elseif direction.Z < -.1 then
HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.p, distination)
end
Humanoid:MoveTo(distination)
return Humanoid.MoveToFinished
end
end
please if this does not solve your problem do not close this topic, I will be happy to help.