So far I have a script that has an NPC following a player, however I want the NPC to fully turn and look at the player with their whole body.
script.Parent:SetPrimaryPartCFrame(CFrame.lookAt(
script.Parent.HumanoidRootPart.Position,target.Position*Vector3.new(1,0,1)
+ script.Parent.HumanoidRootPart.Position*Vector3.new(0,1,0)
))
This is what I’m using to have the NPC turn, and it works technically but I also would like for them to not teleport around?
local larm = script.Parent:FindFirstChild("HumanoidRootPart")
local rarm = script.Parent:FindFirstChild("HumanoidRootPart")
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 10000
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("HumanoidRootPart")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and game.Players:GetPlayerFromCharacter(human.Parent) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while true do
wait(.5)
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent:SetPrimaryPartCFrame(CFrame.lookAt(
script.Parent.HumanoidRootPart.Position,target.Position*Vector3.new(1,0,1)
+ script.Parent.HumanoidRootPart.Position*Vector3.new(0,1,0)
))
script.Parent.Humanoid:MoveTo(target.Position-Vector3.new(-4,-4,-4), target)
end
end
Here is the whole script and here is what’s happening right now.
I understand why it’s doing this but I don’t know how to change it.