Zini So I kind of fixed it by limiting the axes of rotation to one like you said. I look at the mouse movement and if the x movement is bigger I turn horizontally, else I turn vertically. Now this fixed turning horizontally, but vertically, is like a mix between rotating around Z and actually around Y.
func _unhandled_input(event : InputEvent) -> void:
if event is InputEventMouseMotion:
transform = transform.orthonormalized()
if abs(-event.relative.x * SENSITIVITY) > abs(-event.relative.y * SENSITIVITY):
rotate_y(-event.relative.x * SENSITIVITY)
else:
rotate_x(-event.relative.y * SENSITIVITY)
transform = transform.orthonormalized()
As for my solution using two nodes I rotate_y in my rocket scene and send a signal to a child scene which rotate_x's the rocket scene , Scene structure:
rocket(main script)
----MeshInstance3D
----CollisionShape3D
----Camera3D(child script)
main script:
signal rotatex(amount : float)
func _unhandled_input(event : InputEvent) -> void:
if event is InputEventMouseMotion:
rotate_y(-event.relative.x * SENSITIVITY)
rotatex.emit(-event.relative.y * SENSITIVITY)
transform = transform.orthonormalized()
child script:
@onready var parent = get_parent()
func rotatx(amount : float):
parent.rotate_x(amount)
parent.transform = parent.transform.orthonormalized()
If there are syntax errors, they are from typing it here, not in the actual code.