I managed to make non-humanoid NPCs in order for me to be able to place hundreds of them without hurting the game’s performance & everything is handled locally.
I have placed a bunch of nodes (walk points) around the sidewalk and I’m using TweenService to move the characters:
Now, the problem I’m having is that the characters rotation is always set to the node’s orientation. That wouldn’t be a problem if it wasn’t for the fact that the character is going back once he has finished the path, essentially making round-trips in a loop.
Local Script:
for _, node in pairs(array) do
NPC.HumanoidRootPart.CFrame = CFrame.lookAt(NPC.HumanoidRootPart.Position, node.Position)
local goal = {}
goal.CFrame = CFrame.new(node.Position)
local tweenInfo = TweenInfo.new(2.5, Enum.EasingStyle.Linear)
local tween = TweenService:Create(NPC.HumanoidRootPart, tweenInfo, goal)
tween:Play()
tween.Completed:Wait()
end
What should I add to goal.CFrame to make sure the orientation is set to be the NPC pointing to the node instead of taking the node’s orientation?
you should actually add a position to the CFrame’s 2nd parameter, the position to look at.
for _, node in pairs(array) do
NPC.HumanoidRootPart.CFrame = CFrame.lookAt(NPC.HumanoidRootPart.Position, node.Position)
local lookAt = Vector3.new(node.Position.X, NPC.HumanoidRootPart.CFrame.Position.Y, node.Position.Z)
local goal = {}
goal.CFrame = CFrame.new(node.Position, lookAt)
local tweenInfo = TweenInfo.new(2.5, Enum.EasingStyle.Linear)
local tween = TweenService:Create(NPC.HumanoidRootPart, tweenInfo, goal)
tween:Play()
tween.Completed:Wait()
end
Can you see if the HumanoidRootPart of your NPC is rotating or if it’s looking at the node? Just to deduce if it’s a problem with changing its CFrame or the NPC as a whole.
Ah, maybe it was CFrame.Rotation that I meant to put. The new code should actually be goal.CFrame = NPC.HumanoidRootPart.CFrame.Rotation + node.Position.