Trying to make the hand look at mouse but acts weird on some axis

Video

My script that is in starterplayerscripts and obviously is a local script :)

Code:

local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Character = Player.Character or Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local RightShoulder = Character:FindFirstChild("RightShoulder", true)
local YOffset = RightShoulder.C0.Y

local CFNew, CFAng = CFrame.new, CFrame.Angles

game:GetService("RunService").RenderStepped:Connect(function() --Root.CFrame:toObjectSpace(Camera.CFrame).lookVector
	local CameraDirection = Mouse.Hit.LookVector
	if RightShoulder then
		RightShoulder.C0 = CFrame.new(1, YOffset, 0) * CFrame.Angles(0, -math.asin(CameraDirection.X), 0) * CFrame.Angles(math.asin(CameraDirection.Y), 0, 0)
	end
end)

so on axis Z- everything works good
on axis Z+ the X axis is inverse
on axis X+ and X- everything is weird
(these are the axis of the classic baseplate)

idk why it does that
pls help me i tried alot but all in vain

Try:


Oops doesn't work with ur script, lemme make a new one

oh ok lol yea it didnt work haha

when i did with C1 it went kung fu mode lol

I’m not sure but don’t you have to add or subtract 90 degrees from one of the axes when working with shoulder joints?

Also, you could try using the Search button up top for pointing the arm to the mouse position:

How do I make my arm point to the mouse's position?

it dosent even work bruh its for r6

local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Character = Player.Character or Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local RightShoulder = Character:FindFirstChild("RightShoulder", true)
local YOffset = RightShoulder.C0.Y

local CFNew, CFAng = CFrame.new, CFrame.Angles

game:GetService("RunService").RenderStepped:Connect(function() --Root.CFrame:toObjectSpace(Camera.CFrame).lookVector
	local CameraDirection = Root.CFrame:toObjectSpace(Mouse.Hit).lookVector
	if RightShoulder then
		RightShoulder.C0 = CFrame.new(1, YOffset, 0) * CFrame.Angles(0, -math.asin(CameraDirection.X), 0) * CFrame.Angles(math.asin(CameraDirection.Y), 0, 0)
	end
end)

I fixed it lol i just needed to use the Root.CFrame:toObjectSpace(Mouse.Hit).lookVector
Thanks for your help btw

3 Likes
local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local ToolEquipped = false

local Character = Player.Character or Player.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local RightShoulder = Character:FindFirstChild("RightShoulder", true)
local Neck = Character:FindFirstChild("Neck", true)
local YOffset = RightShoulder.C0.Y
local YOffset3 =  Neck.C0.Y

local Tool = nil
Character.ChildAdded:Connect(function(Child)
	if Child:IsA("Tool") then
		ToolEquipped = true
		Tool = Child
	end
end)
Character.ChildRemoved:Connect(function(Child)
	if Child == Tool then
		Tool = nil
		ToolEquipped = false
	end
end)


game:GetService("RunService").RenderStepped:Connect(function()
	local CameraDirection = Root.CFrame:toObjectSpace(Mouse.Hit).lookVector
	if RightShoulder then
		local Offset = CFrame.Angles(math.rad(90), 0, 0)
		if ToolEquipped == true then
			Offset = CFrame.Angles(math.rad(0), 0, 0)
		else
			Offset = CFrame.Angles(math.rad(90), 0, 0)
		end
		Neck.C0 = CFrame.new(0, YOffset3, 0) * CFrame.Angles(0, -math.asin(CameraDirection.X), 0) * CFrame.Angles(math.asin(CameraDirection.Y), 0, 0)
		RightShoulder.C0 = CFrame.new(1, YOffset, 0) * CFrame.Angles(0, -math.asin(CameraDirection.X), 0) * CFrame.Angles(math.asin(CameraDirection.Y), 0, 0) * Offset
	end
end)

Enhanced