How to reduce/eliminate client latency from AlignOrientation?

Hi, Tophat here.

I’m trying to make a humanoid look at the player, and I’m using AlignOrientation to achieve this (setting the CFrame/Orientation directly makes it stutter while walking).

Now, it somewhat works, but there’s a noticeable delay in aligning on the client, compared to the server. Below is a video of what it looks like on the client, and on the server.

I would like to replicate what the AlignOrientation is doing on the server on the client, so there is no delay.

Here is the code I’m using to create and set the attachments, constraint and their CFrames. (Server Script):

local AlignAttachment = Instance.new("Attachment")
AlignAttachment.Parent = workspace.AttachmentHolder

local AlignOrientation = Instance.new("AlignOrientation")
AlignOrientation.Parent = script.Parent.Parent.HumanoidRootPart
AlignOrientation.MaxTorque = 400000
AlignOrientation.Responsiveness = 100
AlignOrientation.Attachment0 = script.Parent.Parent.HumanoidRootPart.RootAttachment
AlignOrientation.Attachment1 = AlignAttachment

-- "RootPart" is the player character's HumanoidRootPart
AlignAttachment.CFrame = CFrame.new(script.Parent.Parent.HumanoidRootPart.Position, RootPart.Position)

while task.wait() do
	AlignAttachment.CFrame = CFrame.new(script.Parent.Parent.HumanoidRootPart.Position, RootPart.Position)
end

I would greatly appreciate some help with this issue, thanks.

For starters instead of setting Responsiveness & all, set RigidityEnabled to true.
“When true, the solver reacts as quickly as possible to complete the alignment.” → This is exactly what you want!

The second thing is that I am not entirely sure whether or not Roblox does the orientation calculations on each client or waits for the server to replicate the updated orientation. I would personally create the alignments on the Client’s to ensure that it is always up to date with your client instead of the server version of the client’s position.

Your current position takes time to be updated on the server so when you move on your screen the orientation will always look towards you but never get to you fast enough while moving until you stand still.

1 Like

For some reason, creating the constraint on the client doesn’t seem to affect the NPC at all now. I’ve tried testing it with a normal part (network ownership not affected), where it works, but with a humanoid, it isn’t rotating.

Update: So it somewhat works, but now it sometimes has severe delays in updating (several seconds pass before it decides to align itself), and sometimes it stops aligning itself if you move away far enough.