Making a player's head face a part using a Motor6D

Please tell me how to do this. I have tried every single possibility under the sun. I cannot figure it out.

I tried using this:
Head.CFrame = Head.CFrame * CFrame.Angles(CFrame.new(Head.Position, LookAt.Position):ToEulerAnglesXYZ())

And this:

Neck.C1 = baseC1 * CFrame.Angles(CFrame.new(baseC1.Position, LookAt.Position):ToEulerAnglesXYZ())

And last, but definitely least:

Neck.C0 = CFrame.new(Neck.C0.Position, LookAt.Position)

I’m pretty my last 36 searches have been revolving around this stupid topic and I hate it.

My closest attempt was probably this: https://streamable.com/p3n9xm (i still can’t upload videos)

…help please

2 Likes

I’ve written up a simple localscript sample you can place in the “StarterCharacterScripts” folder that’s intended for a R6 rig.
You would have to analyze this to fit your needs.

--Initialization
local torso = script.Parent:WaitForChild"Torso" --get reference to Torso, change this as needed
local targetPos = Vector3.new(0,0,0) --Change this as needed
local OrigC1 = torso.Neck.C1 --store the original C1 value for transformation

--Runtime

game:GetService"RunService".Stepped:connect(function()
	local torsoF = torso.CFrame.LookVector--Get the directional vector which the torso is facing
	local torsoR = torso.CFrame.RightVector--Get the directional vector that extends right of the torso
	local actualVect = targetPos - torso.CFrame.Position---Get the directional vector from torso to target
	
	local rot = math.atan2(torsoR:Dot(actualVect),torsoF:Dot(actualVect))
	--Dot determines how much the target vect faces the torso vectors
	--By doing this, we can construct "relative" coordinates as opposed to "absolute" coordinates.
	--We can then determine the relative angle from these coordinates using atan2
	torso.Neck.C1 = CFrame.Angles(0,rot,0) * OrigC1
	--Sets the neck every step
end)

The final rotation is based off the current orientation of the HumanoidRootPart relative to the orientation necessary for the target.

5 Likes

waddu hek

wow I didn’t expect it to be that easy and the fact that it is angers me lol
and thanks for the comments in the code, helps alot. cheers!

Sorry for necroposting, but I’m facing a similar issue with R6 Arms.
I modified your code

--Initialization
local torso = script.Parent:WaitForChild("Torso") --get reference to Torso, change this as needed
local targetPos = Vector3.new(0,0,0) --Change this as needed
local OrigC1 = torso["Right Shoulder"].C1 --store the original C1 value for transformation

--Runtime

game:GetService("RunService").Stepped:Connect(function()
	targetPos=workspace.Target.Position
	local torsoF = torso.CFrame.LookVector--Get the directional vector which the torso is facing
	local torsoR = torso.CFrame.RightVector--Get the directional vector that extends right of the torso
	local actualVect = targetPos - torso.CFrame.Position---Get the directional vector from torso to target

	local rot = math.atan2(torsoR:Dot(actualVect),torsoF:Dot(actualVect))
	--Dot determines how much the target vect faces the torso vectors
	--By doing this, we can construct "relative" coordinates as opposed to "absolute" coordinates.
	--We can then determine the relative angle from these coordinates using atan2
	torso["Right Shoulder"].C1 = CFrame.Angles(rot,rot,rot) * OrigC1
	--Sets the neck every step
end)