Make gun follow mouse

I want to make the gun aim where the mouse aims.

Issue is that most approaches i try usually fail or look really weird

I tried making shoulders face the mouse but it usually failed, didnt work as expected

Any help is appreciated

We need a script to help you with your script.

1 Like
I used this script
local mouse_hit_attachment = Instance.new("Attachment")
mouse_hit_attachment.Name = "mouse_hit_attachment"
mouse_hit_attachment.Parent = character

local head_ik_control = Instance.new("IKControl")
head_ik_control.Name = "head_ik_control"
head_ik_control.Parent = character
head_ik_control.Target = mouse_hit_attachment
head_ik_control.ChainRoot = character:FindFirstChild("UpperTorso")
head_ik_control.EndEffector = character:FindFirstChild("Head")
head_ik_control.Weight = 0
head_ik_control.Type = Enum.IKControlType.LookAt

local right_hand_ik_control = Instance.new("IKControl")
right_hand_ik_control.Name = "right_hand_ik_control"
right_hand_ik_control.Parent = character
right_hand_ik_control.Target = mouse_hit_attachment
right_hand_ik_control.ChainRoot = character:FindFirstChild("RightUpperArm")
right_hand_ik_control.EndEffector = character:FindFirstChild("RightHand")
right_hand_ik_control.Weight = 0
right_hand_ik_control.Type = Enum.IKControlType.Rotation
...

local right_hand = character:WaitForChild("RightHand") :: BasePart
local mouse = player:GetMouse()

run_service.PreRender:Connect(function()
	-- compensate right hand rotation
	local angles = CFrame.Angles(math.pi / 2, 0, math.pi)
	local mouse_position = mouse.Hit.Position + mouse_offset.Value -- mouse_offset can be safely removed
	mouse_hit_attachment.WorldCFrame = CFrame.lookAlong(mouse_position, right_hand.Position - mouse_position) * angles
end)

here (still in progress) : First Person Camera With Weapons [TEST PROJECT] - Roblox

How it works (written for R15):

  • it uses two IKControls and one attachment to control orientations of head and right hand, so head and hand look at mouse position (it’s somewhat awkward when the mouse is behind character, it’s in my todo list)
  • at the moment character equips weapon - set IKControls’ weights to 1 or enable them, do opposite when weapon unequipped
1 Like

i have kinda fixed it, works well enough

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.