FPS arm rotation won't clamp and arms rotate behind camera

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BuddyGames

I used the following code to make the arms in the model rotate along with the camera. The arms holding the gun end up continuing to rotate past the head. I’ve also tried clamping it to the camera’s rotation, using inverse kinematics and making the arms children of the camera and just rotating the camera. IK won’t work because I couldn’t use better collada as it seems to be broken, so I’m just using a GLTF model. This makes it so that the bones in the mesh are just spatial nodes, and I made the mesh out of modular pieces and didn’t combine them, so each ones has either a child spatial or a mesh for that body part or both. Different kinds of clamping either break the camera’s clamp or somehow rotate it on the Y axis. Here’s my code:

func _input(event):
if event is InputEventMouseMotion:
	rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
	head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
	head.rotation.x = clamp(head.rotation.x, deg2rad(-80), deg2rad(80))
	
	
	leftshoulder.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
	
	leftshoulder.rotation.x = clamp(rightshoulder.rotation.x, deg2rad(-80), deg2rad(80))
	
	
	rightshoulder.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
	rightshoulder.rotation.x = clamp(rightshoulder.rotation.x, deg2rad(-80 ), deg2rad(80))