How to make an arm follow the mouse using Motor6Ds

So I’ve been trying to make a script where the arm follows the mouse using Motor6Ds for the past few weeks.
All I’ve ended up with were failed attempts and I haven’t inched much closer to the solution myself.

while true do wait() workspace.Dummy.Torso["Right Shoulder"].C1 = workspace.Dummy.Torso["Left Shoulder"].C1*CFrame.fromEulerAnglesXYZ(math.rad(-workspace["Right Arm"].Orientation.Y),math.rad(workspace["Right Arm"].Orientation.Z),math.rad(workspace["Right Arm"].Orientation.X))
 end

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

The idea is to do this, but I don’t know what RX and RY and RZ are supposed to be. I’m searching for the equation.

workspace.Dummy.Torso["Right Shoulder"].C1 = workspace.Dummy.Torso["Left Shoulder"].C1*CFrame.fromEulerAnglesXYZ(math.rad(RX),math.rad(RY),math.rad(RZ))

Like this

1 Like