R6 arms follow camera, but only on local axis


On my character I have the arms following the camera. They work fine when the torso is facing directly forward, but when the torso is rotated at all, the arms no longer follow the camera. In the video, this problem specifically happens on the Y axis.
This happens because I only manipulate the arm’s cframe on its local axis. I want the arms and gun to perfectly follow the camera. How would I rotate them on a global axis? Or is there any other way to accomplish this?
Here is the code I have right now (in the form of pseudocode):

local function RenderStepped()
	local cameraDirection = rootPart.CFrame:ToObjectSpace(camera.CFrame).LookVector
	rightShoulder.C0 = (CFrame.new(rootJoint.C0.Position + Vector3.new(0, 0.5, 0)) * 
		CFrame.Angles(0, -math.asin(cameraDirection.X), 0) * 
		CFrame.Angles(math.asin(cameraDirection.Y), 0, 0) * 
		CFrame.Angles(0, math.pi / 2, 0)) * 
		CFrame.new(0, 0, 1)
end
1 Like

I cant help, but I have been trying to acheive this for a while, can you share the script?

I looked at your recent posts and see that you’re trying to implement a first-person viewmodel. I think it’s better to implement fps arms a different way, like in this post here: Writing an FPS framework (2020) - Resources / Community Tutorials - DevForum | Roblox

Thank you, I fixed it using a viewmodel, the gun looks really bad with it but atleast it looks a bit better

for example when I aim down the gun bullet comes from far away, but it still hits the part I want so im glad I could fix it

You have tried

local cameraDirection = rootPart.CFrame:ToWorldSpace(camera.CFrame).LookVector

instead of

local cameraDirection = rootPart.CFrame:ToObjectSpace(camera.CFrame).LookVector

yet?

Nvm you fixed it already