Camera clamp not working when the camera is tilted on a Z Axis

@pennyloafers hey man, did it work?

i think i found the issue.

camera.rotation.z = sin(t_bob * BOB_FREQ_Y) * BOB_AMP_Y

when we start to bob head, our basis is no longer square with the world

and this code (as well as the previous code)

camera.rotation.x = -deg_to_rad(85) * sign(camera.transform.basis.z.y)

is making the wrong assumption about the x rotation. I think what happens is that we set the rotation and it causes the y axis to flip because we are setting the x ration to an impossible value that is only resolved by flipping the y axis, this is Euler’s fault… I think we need to use quaturnian in some way but i’m not smart enough to figure that out.

to fix this we need to rotate another way.

I fixed this with using your head instead of camera

@onready var head = $Pivot/Head
...
func _headbob(time) -> Vector3:
    ...
	head.rotation.z = sin(t_bob * BOB_FREQ_Y) * BOB_AMP_Y
1 Like

oh my god it’s actually fixed, thank you so much brother, i will study more and take notes, you’re the best!

sorry that took me so long, I was a little baffled.

I think there is a trade off though with using the head, there is no advantage to using rotate_object_local as it won’t counter the head rotation since it isn’t happening on the camera anymore. this is only minor, and its up to you if that is a desired trait.

Don’t worry, it’s all good now, thanks for helping me :laughing:

sorry one last note

I was also able to still use the camera if I changed the axis order on the camera to X axis first
defualt: YXZ
updated XYZ

image

This also solves the issue, I think its because it basically makes X the master axis by rotating on it first.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.