Godot Version
4.2.1.stable.mono
Question
Hey all! I am wanting to leave Euler angles behind, and switch over to Transforms & Quaternions. I am having a problem though. I want to Clamp()
the angle (in radians) that the Player
can look up or down, but there are no “angles” in a transforms basis.
So how do I go about clamping such a rotation?
2 Likes
I am also working on this. I think I am close. Be warned, I think it is going to be a lot uglier (code wise) but much better in the long run. I believe it’ll be possible to abstract, and clean it up a bit. If I get an answer, I’ll respond.
Just know you’re not the only one!
I can post the full code if you want, but here’s what I got.
func _handle_mouse_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
# Rotate the x axis gimbal.
var rotation_amount_x: float = event.relative.x * mouse_rotation_speed
var player_camera_basis_result: Basis = Basis(Vector3.DOWN, rotation_amount_x) *player_camera.basis
player_camera.transform.basis = player_camera_basis_result
# Rotate the y axis gimbal.
var rotation_amount_y: float = event.relative.y * mouse_rotation_speed
var marker_3d_basis_result: Basis = Basis(Vector3.LEFT, rotation_amount_y) * player_camera.marker_3d.basis
marker_3d_basis_result.y = marker_3d_basis_result.y.clamp(Vector3(0, 0, -1), Vector3(0, 1, .1))
player_camera.marker_3d.transform.basis = marker_3d_basis_result