I have searched for answers on the devforum, but haven’t found anything related to my issue. I’ve also tried both making the humanoidrootpart the chainroot and welding a part to the head and making that the chainroot, but with no luck. Any ideas?
You can actually just use the neck joint if you’d like:
local lookAtThis = workspace:WaitForChild('LookAtThis')
local character = script.Parent
local root = character:WaitForChild('HumanoidRootPart')
local neck = character:WaitForChild('Head'):WaitForChild('Neck')
local y = neck.C0.Y
local function clampUnit(x)
return math.clamp(x,-1,1)
end
local function pointHeadTowards(targetPos:Vector3)
local toTarget = targetPos - root.Position
if toTarget.Magnitude < 1e-3 then return end
local dirLocal = root.CFrame:VectorToObjectSpace(toTarget.Unit)
local pitch = math.asin(clampUnit(dirLocal.Y))
local yaw = -math.asin(clampUnit(dirLocal.X))
local MAX_PITCH = math.rad(35)
local MAX_YAW = math.rad(60)
pitch = math.clamp(pitch,-MAX_PITCH,MAX_PITCH)
yaw = math.clamp(yaw,-MAX_YAW,MAX_YAW)
neck.C0 = CFrame.new(0,y,0)*CFrame.Angles(pitch,yaw,0)
end
while true do
pointHeadTowards(lookAtThis.Position)
task.wait(.01)
end
Here’s a simpler, but less customizable, version:
local lookAtThis = workspace:WaitForChild('LookAtThis')
local character = script.Parent
local root = character:WaitForChild('HumanoidRootPart')
local neck = character:WaitForChild('Head'):WaitForChild('Neck')
local y = neck.C0.Y
local function pointHeadTowards(position:Vector3)
local lookCF = CFrame.lookAt(root.Position,position)
local camLook = root.CFrame:ToObjectSpace(lookCF).LookVector
neck.C0 = CFrame.new(0,y,0)*CFrame.Angles(math.asin(camLook.Y),-math.asin(camLook.X),0)
end
while true do
pointHeadTowards(lookAtThis.Position)
task.wait(0.01)
end
I’d obviously recommend doing this client-side and also using RenderStepped, but optimize it to only work when near enough to the player to be worth doing.
Thank you very much! Though I don’t need the script since I’m using IKControl, but using the neck joint as the chainroot works perfectly. I still have one issue remaining though: like in the image in my post, the head is still tilted. It does faces the player, but in a tilted and unstable way. Any ideas? I hear that IKControl is fairly optimized, so I’d like to not have to replace it.
I’ve honestly avoided IKControl for the time being as I’ve found it to be very jank. I think there’s a way to apply restrictions to it to make it better, but I don’t really know much about that.
Here’s something I asked at one of the previous Creator AMA’s:
Thanks to @MightyDantheman, I know now that all I had to do to make only the head affected by the IKControl was to make the neck motor6D inside the torso the chainroot.
And as for the tilting and bending problem that I also mentioned here and that can be seen in the image in the post, I was given a solution for that in a separate post I made, and that solution is to simply make an idle animation affecting the parts being moved by the IKControl to prevent the IKControl from using the previous transform when updating. NPC bending into unnatural positions with IKControl lookAt - #5 by TEARAPARTJAMES