Arms Are Acting Weird

Hi
I’m trying to make a first-person shooter, and I am using a script to make the arms face the camera direction when a weapon is equipped. The problem is that in first-person the arms look too close or too far away from the camera when looking up or down.

Video:

Script Responsible For “Arms To Cam”:

  • Inside Each Weapon (Local Script)
-- Raise Hand --
run.RenderStepped:Connect(function()
	if equipped then
		local char = plr.Character or plr.CharacterAdded:Wait()
		
		local params = RaycastParams.new()
		params.FilterType = Enum.RaycastFilterType.Blacklist
		params.FilterDescendantsInstances = {char, workspace:WaitForChild("FX")}
		params.IgnoreWater = true

		local VIEWPORT_SIZE = cam.ViewportSize -- current size of the screen -- if you're raycasting multiple times, this will have to be redefined!
		local CAST_LENGTH = 100 -- distance to raycast

		local unitRay = cam:ScreenPointToRay(VIEWPORT_SIZE.X / 2, VIEWPORT_SIZE.Y / 2 - game:GetService("GuiService"):GetGuiInset().Y) -- account for the 36px TopBar inset
		local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * CAST_LENGTH, params)

		local pos
		local posTwo = cam.CFrame.Position

		if raycastResult and raycastResult.Position then -- .Position is the Vector3 (the Hit.Position) of the center of the screen
			pos = raycastResult.Position
		else
			pos = unitRay.Origin + unitRay.Direction * CAST_LENGTH
		end
		
		local rightX, rightY, rightZ = char.Torso["Right Shoulder"].C0:ToEulerAnglesYXZ()
		char.Torso["Right Shoulder"].C0 = (char.Torso["Right Shoulder"].C0 * CFrame.Angles(0, 0, -rightZ)) * CFrame.Angles(0, 0, math.asin((pos - posTwo).unit.y))
		if reloading then
			local leftX, leftY, leftZ = char.Torso["Left Shoulder"].C0:ToEulerAnglesYXZ()
			char.Torso["Left Shoulder"].C0 = (char.Torso["Left Shoulder"].C0 * CFrame.Angles(0, 0, -leftZ)) * CFrame.Angles(0, 0, math.asin((-pos - -posTwo).unit.y))
		end
	end
end)

Can someone help me fix it?

2 Likes

Are you using a custom camera system?
If so I would personally make the camera pivot about the horizontal shoulder line where the arms rotate about, but with some offset to make it actually your head
This would also give the effect of actually looking downwards rather than your neck going 180 degrees up or down too

1 Like

Sorry I don’t really know what you mean. Also I’m not using a custom camera system.

1 Like

Thats because you are moving the arm relative to the torso which mean you are moving its Motor6D CFrame which is connected to the torso

1 Like

So should I try moving them relative to the player’s head?
If so, how would I go about that since the arms are connected to the torso.

1 Like

i know a great script that moves tool to camera Smooth First Person Arms Movement - Roblox

which mean relative to camera

2 Likes