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