Making NPC face target position

So I’ve been working on the logic for my combat NPC’s, and I’ve found this issue where trying to make the NPC move while facing a specified point doesn’t work, the NPC’s orientation changes but it can’t move.

Here’s the code I’m using:

NPC.Model.HumanoidRootPart.CFrame = CFrame.lookAt(NPC.Model.HumanoidRootPart.Position,target.HumanoidRootPart.Position,NPC.Model.HumanoidRootPart.CFrame.UpVector)

-This code is nested within a while loop that’s running on the server by the way

1 Like

using alignorientation would be easier and not mess up the cframe

local NPC = script.Parent
local NPCRoot = NPC:WaitForChild("HumanoidRootPart")

local Align = Instance.new("AlignOrientation")
Align.Mode = Enum.OrientationAlignmentMode.OneAttachment
Align.MaxAngularVelocity = 1e6
Align.Responsiveness = 200 
Align.MaxTorque = 1e4
Align.Attachment0 = NPCRoot.RootAttachment
Align.Parent = NPCRoot

local FaceTarget = function(Char)
	local Root = Char:WaitForChild("HumanoidRootPart")
	
	local CF = CFrame.new(NPCRoot.Position, Root.Position)
	Align.CFrame = CFrame.Angles(CF:ToEulerAnglesXYZ())
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.