Align camera with horizon

Godot Version



How do I align the camera with the horizon such that the horizon is always on a horizontal line compared to the screen. Currently I’ve been using the looking at function with Vector3.UP as the up direction. This works fine but bugs out when looking straight up and down. How would I make this work.

Currently my code to align it looks like this
var a = Transform3D(camera_aim, Vector3.ZERO) camera_aim = a.looking_at(-camera_aim.z).basis

If it helps I’m trying to create a war thunder like plane controller. Example

something like this ?

func _process(delta):
	camera.rotation_degrees.z = 0

for godot 4

func _process(delta):
	$Camera3D.rotation.z = 0

Sorry. Forgot to mention that I’ve already tried this. It has a similar issue to the using look_at being that the camera starts jumping around much when looking straight up.