Arm follow camera script makes arms teleport inside torso

I made a script that makes the arms and head follow the camera on the Y axis for R15 and R6 characters for my FPS game. The head works fine but the arms are in places that they shouldn’t be in, like in the head and torsos position. Please help as I have tried lots of ways to fix the arms!

R6:
robloxapp-20211121-1301289.wmv (716.4 KB)

R15:
robloxapp-20211121-1302556.wmv (1.1 MB)

This is the script:

local tweenService = game:GetService("TweenService")

local Camera = workspace.CurrentCamera
local Player = game.Players.LocalPlayer

local Character = Player.Character
local Root = Character:WaitForChild("HumanoidRootPart")
local Neck = Character:FindFirstChild("Neck", true)
local YOffset = Neck.C0.Y

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

game:GetService("RunService").RenderStepped:Connect(function()
    local CameraDirection = Root.CFrame:toObjectSpace(Camera.CFrame).lookVector
    if Neck then
		if Character.Humanoid.RigType == Enum.HumanoidRigType.R15 then
			Neck.C0 = CFNew(0, YOffset, 0) * CFAng(asin(CameraDirection.y), 0, 0)
			local YOffset2 = Character.RightUpperArm.RightShoulder.C0.Y
			local YOffset3 = Character.LeftUpperArm.LeftShoulder.C0.Y
			Character.RightUpperArm.RightShoulder.C0 = CFNew(0, YOffset2, 0) * CFAng(asin(CameraDirection.y), 0, 0)
			Character.LeftUpperArm.LeftShoulder.C0 = CFNew(0, YOffset3, 0) * CFAng(asin(CameraDirection.y), 0, 0)
		elseif Character.Humanoid.RigType == Enum.HumanoidRigType.R6 then
			Neck.C0 = CFNew(0, YOffset, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(-asin(CameraDirection.y), 0, 0)
			local YOffset2 = Character.Torso['Right Shoulder'].C0.Y
			local YOffset3 = Character.Torso['Left Shoulder'].C0.Y
			Character.Torso['Right Shoulder'].C0 = CFNew(0, YOffset2, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(-asin(CameraDirection.y), 0, 0)
			Character.Torso['Left Shoulder'].C0 = CFNew(0, YOffset3, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(-asin(CameraDirection.y), 0, 0)
		end
    end
end)

game.ReplicatedStorage.Look.OnClientEvent:Connect(function(otherPlayer, neckCFrame)
	local Neck = otherPlayer.Character:FindFirstChild("Neck", true)
	if Neck then
		tweenService:Create(Neck, TweenInfo.new(.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {C0 = neckCFrame}):Play()
	end
end)
2 Likes

the x axis of your cframes for the arms need to be either 1 or -1.

--R15
Character.RightUpperArm.RightShoulder.C0 = CFNew(1, YOffset2, 0) * CFAng(asin(CameraDirection.y), 0, 0)
Character.LeftUpperArm.LeftShoulder.C0 = CFNew(-1, YOffset3, 0) * CFAng(asin(CameraDirection.y), 0, 0)

--R6
Character.Torso['Right Shoulder'].C0 = CFNew(1, YOffset2, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(-asin(CameraDirection.y), 0, 0)
Character.Torso['Left Shoulder'].C0 = CFNew(-1, YOffset3, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(-asin(CameraDirection.y), 0, 0)

Thanks! this fixed the R15 problem, but for R6 it makes the arms face forward like a zombie

do you need to multiply the cframe by (math.pi \ 2) * 3?

Character.Torso['Right Shoulder'].C0 = CFNew(1, YOffset2, 0) * CFAng(asin(CameraDirection.y), 0, 0)
Character.Torso['Left Shoulder'].C0 = CFNew(-1, YOffset3, 0) * CFAng(asin(CameraDirection.y), 0, 0)

I guess not because the facing forward problem was fixed but that causes the arms to facing sideways

The animations are default roblox animations too

that problem is probably the y rotation

Character.Torso['Right Shoulder'].C0 = CFNew(1, YOffset2, 0) * CFAng(asin(CameraDirection.y), rad(90), 0)
Character.Torso['Left Shoulder'].C0 = CFNew(-1, YOffset3, 0) * CFAng(asin(CameraDirection.y), rad(-90), 0)

if that doesn’t work, then try this

Character.Torso['Right Shoulder'].C0 = CFNew(1, YOffset2, 0) * CFAng(asin(CameraDirection.y), rad(-90), 0)
Character.Torso['Left Shoulder'].C0 = CFNew(-1, YOffset3, 0) * CFAng(asin(CameraDirection.y), rad(90), 0)
2 Likes

Thanks so much! I couldn’t find a solution to this problem so this helped alot!