First get the position of the mouse in 3d workspace.
Then get the rough position of the Motor6D in workspace.
Then make a CFrame pointing towards the mouse position from the Motor6D’s position.
Then get it’s x rotational component.
Then apply the rightShoulder’s offset and the x rotational component to the right shoulder.
local Player = game.Players.LocalPlayer
local Character = script.Parent
local RightShoulder = Character:FindFirstChild("Right Shoulder",true)
local Torso = Character:WaitForChild("Torso")
local Mouse = Player:GetMouse()
local rightShoulder_C0 = RightShoulder.C0
game:GetService("RunService").RenderStepped:Connect(function()
local mousePosition = Mouse.Hit.Position
local C0toMouse = CFrame.new((Torso.CFrame*rightShoulder_C0).Position,mousePosition)
local x,0,_ = C0toMouse:ToOrientation()
RightShoulder.C0 = rightShoulder_C0*CFrame.Angles(0,0,x)
end)
Oh you want y axis as well? Here is the updated code then:
local Player = game.Players.LocalPlayer
local Character = script.Parent
local RightShoulder = Character:FindFirstChild("Right Shoulder",true)
local Torso = Character:WaitForChild("Torso")
local Mouse = Player:GetMouse()
local rightShoulder_C0 = RightShoulder.C0
game:GetService("RunService").RenderStepped:Connect(function()
local mousePosition = Mouse.Hit.Position
local C0toMouse = CFrame.new((Torso.CFrame*rightShoulder_C0).Position,mousePosition)
local x,y,_ = C0toMouse:ToOrientation()
RightShoulder.C0 = rightShoulder_C0*CFrame.Angles(0,y,x) -- Just add y here.
end)
If i look in the right direction, it looks completely normal. However when i turn in any other direction, the arms starts to enter the body or starts going into weird places.