I can't seem to get the right r6 arm to follow where the mouse is

Ok so basically https://gyazo.com/2840a047bbcfaccfdf45ca6c1b6098e1 I’ve tried all the solutions with trying to find the right cframe, the current code right now is

local ArmJoint = Character.Torso[“Right Shoulder”]

spawn(function()
local OffsetY = ArmJoint.C0.Y

local CFN, CFA, A, T = CFrame.new, CFrame.Angles, math.asin, math.tan

game:GetService(“RunService”).RenderStepped:Connect(function()
if script.Parent:FindFirstChild(“Gun”) then
if ArmJoint then
local MouseCF = Root.CFrame:ToObjectSpace(Mouse.Origin).lookVector

  		ArmJoint.C0 = CFN(ArmJoint.C0.Position) * CFrame.Angles(0, 0, -T(MouseCF.X)) * CFrame.Angles(0, T(MouseCF.Y), 0)
  		wait()
  	end
  end

end)
end)

and I’m trying to make the arm face turn towards the mouse.
Please reply with help!

1 Like

Are you sure your trigonometry math is correct, getting the right values to do the math.atan operations?, and CFrame order of operations as well, because the axis of rotation might change when you use CFrame.Angles perhaps use CFrame.fromAxisAngle if you want to clearly define an axis of rotation for a CFrame.

See here for vector maths to see what happens you a math.atan a vector:

To find the vertical angle of elevation you got to math.atan( Y / sqrt(X^2 + Z^2)) in that scenario.

Otherwise, Instead of trying to find the CFrame in terms of the motor object CFrame as you are doing right here:

You can just inverse the part0 CFrame then obtain the CFrames of the arm relative to the world which I believe is much easier to handle as this post suggests.

1 Like