Hello,
I am quite new to 3D development, so I thought a good way to learn was to try and create some simplistic 3D editor integrated with Godot. My camera will point towards a focal point (similar to the regular 3D editor). I haven't integrated the handling of the mouse input yet, but I have added some simplistic code to move the camera each frame. It seems to work as it is, but I'm not sure it is the best approach. What I'm currently doing is:
- Rotate the camera along the Y axis of the target
- Compute the cross product between the new position of the camera and the target's Y axis
- Rotate the camera along the computed axis
I then point the camera towards the target and orthonormalize the transform, just in case. I've searched Google for better ways to do this and they all mention using a parent Spatial (or even two) and rotating that in order for Godot to automatically rotate the camera, but I failed to produce the same results with that method.
For reference the code I'm using so far in the _process function is:
transform.origin = transform.origin.rotated(_target.transform.basis.y, deg2rad(5))
var rot_y = sin(float(Time.get_ticks_msec()) / 1_000)
var axis = transform.origin.cross(_target.transform.basis.y).normalized()
transform.origin = transform.origin.rotated(axis, deg2rad(rot_y))
transform = transform.looking_at(_target.transform.origin, _target.transform.basis.y)
transform.orthonormalized()
Any help would be extremely appreciated!! Thanks 😄