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.
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)