How do i make my character's arm point to the mouse

I want the character’s arms point to the mouse whilst it has a tool equipped.

This is what i currently have, but it only makes the arms move up and down whilst pointing at the cursor, but not left and right.

RightShoulderCFrame = CFrame.new(1,0.5,0) * CFrame.Angles((-math.asin((mouseOrigin.p - mouseHit.p).unit.y)+0.015),1.55,0)
LeftShoulderCFrame = CFrame.new(-1,0.5,0) * CFrame.Angles((-math.asin((mouseOrigin.p - mouseHit.p).unit.y)+0.015),-1.55,0)
toolEvent:FireServer(RightShoulder,RightShoulderCFrame, LeftShoulder,LeftShoulderCFrame)

This is what i want to achieve. The arms point left, right, up and down. Causing the arms to point exactly at the mouse.
image

3 Likes

It’s quite simple really!

All you have to do is :-

  • 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)
1 Like

Thanks for the explanation. I’ve been tinkering with this but i can’t seem to make the arm go left and right aswell. It only goes up and down.

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)

Sorry for late response, time zones really suck.

2 Likes

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

1 Like

anyone revisit this code please

1 Like

Rather than reviving a month old post, simply make a new one.

Same result. What’s the big deal?

Better to use old post rather than making a new one