kuligs2
This is trivial, not sure why it's causing so much confusion.
Construct the rotation matrix and transform object's relative (to rotation origin) position by it. In the case of camera orbiting, the matrix you want is probably composed of delta rotations around up and local right axes. For camera, you'd also want to aim it at the rotation origin after each rotation.
extends Camera3D
@onready var target = $"../target"
const SENSITIVITY = .02
func orbit_point(origin: Vector3, point: Vector3, orbit_angle: Vector2) -> Vector3:
var d = point - origin
var t = Transform3D().rotated(Vector3.UP, orbit_angle.x).rotated(-d.cross(Vector3.UP).normalized(), orbit_angle.y)
return origin + t * d
func _input(e):
if e is InputEventMouseMotion:
global_position = orbit_point(target.global_position, global_position, e.relative*SENSITIVITY)
look_at(target.global_position)