Godot Version
4
Hi. I have a system in use where when I move to the left or the right, the camera has a slight sway to add a sense of “weight” to the character. However, after moving to the left or right and ‘activating’ the sway, the camera clamp breaks, allowing me to do a full 360.
How are you doing the clamp?
This is my head clamp code
“if event is InputEventMouseMotion:
rotate_y(-event.relative.x * mouse_sens)
head.rotate_x(-event.relative.y * mouse_sens)
head.rotation.x = clamp(head.rotation.x, deg_to_rad(-89), deg_to_rad(89))”
But I think it’s clashing with this code.
“if input_dir .x>0:
head.rotation.z = lerp_angle(head.rotation.z, deg_to_rad(-4.5), 0.05)
elif input_dir .x<0:
head.rotation.z = lerp_angle(head.rotation.z, deg_to_rad(4.5), 0.05)
else:
head.rotation.z = lerp_angle(head.rotation.z, deg_to_rad(0), 0.05)”
You’re likely going to run into problems with that; gimbal lock in particular. Essentially, euler angles are applied in sequence, not all at once, so if you rotate nearly 90 degrees in x, z is now rotating on a very different axis.
You might want to consider instead having four quaternions at the extremes of rotation and interpolate between them.