How to rotate camera around object in 3D using two axes?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bborncr

I am trying to rotate a camera around a FocusPoint (Spatial). The camera is child of FocusPoint. The code below works as long as only one axis is rotated at a time. It quickly goes all wonky when both axes are used. I have been reading the Godot 3D docs and trying to understand Transforms but I need some tips.

if event is InputEventMouseMotion and is_camera_dragged:
		$FocusPoint.rotate_object_local(Vector3(0,0,1), event.relative.y * PI/360)
		$FocusPoint.rotate_object_local(Vector3(0,-1,0), event.relative.x * PI/360)
:bust_in_silhouette: Reply From: brainbug

Use a gimbal
1 Spatital per Axis

outer
— inner
--------------camera

So simple and works great!!

Thanks!

  if event is InputEventMouseMotion and is_camera_dragged:
      $FocusPoint/Gimbal.rotate_object_local(Vector3(0,0,1), event.relative.y * PI/360)
      $FocusPoint.rotate_object_local(Vector3(0,-1,0), event.relative.x * PI/360)

bborncr | 2019-04-16 19:37