The NPC’s in my game have localized head tracking to follow players when in-range. However, there has been a random bug occuring where the NPC’s head will fall into the NPC torso (see image below). I am not entirely sure why this is happening, my early assumption was that the joint didn’t exist early enough so I tried anchoring the heads until they need to be moved with no luck. The script below uses the default “Neck” Motor6D found in the character head.
Bug Image
Head Code
self.connections["head"] = RunService.Heartbeat:Connect(function()
local character, root = GetLocalCharacter()
if (not character) or (not root) then
return
end
local direction = (CFrame.new(self.position,root.Position):Inverse() * self.cframe ).lookVector * -1
if self.personality.UseYAxis then
self.neck.C0 = CFrame.new(0, self.neck.C0.Y, 0) * CFrame.Angles(0, -math.asin(direction.x), 0) * CFrame.Angles(math.asin(direction.y), 0, 0)
else
self.neck.C0 = CFrame.new(0, self.neck.C0.Y, 0) * CFrame.Angles(0, -math.asin(direction.x), 0)
end
end)
Any help is much appreciated!