Help with Camera3D, Rotation and Basis

Godot Version

Godot 4.2.1 Stable

So, I want to create a game like The Sims (Life Simulation), but amazingly, the thing that got me was camera rotation. Basically, I have a camera system where you can zoom in and out, rotate in 45º if press Z or X and if you click and drag the right mouse button, you can move the camera. The problem is that the camera movement is locked to the Global Axis, instead of the Local Camera axis. So, if I rotate the camera, the movement will not follow the camera view, and will instead, move to the global axis. I tried so many things, and I never EVER managed to get this thing right.

Here is a little video showing the camera:

I organized the system like this:

Point_Camera (Node3D)
Camera (Camera3D)

And lastly, here is the full code for this camera system:

extends Node3D

var camera_zoom := 0.0
var camera_drag := Vector2.ZERO
var camera_movement := Vector3.ZERO
var sensibility := 0.001

func _process(delta):
	if Input.is_action_just_pressed("b_zoom_in"):
		camera_zoom -= 0.5
	if Input.is_action_just_pressed("b_zoom_out"):
		camera_zoom += 0.5
	$Camera.position.z += camera_zoom
	$Camera.position.z = clamp($Camera.position.z,10,50)
	camera_zoom = lerpf(camera_zoom,0.0,0.2)
	if Input.is_action_just_pressed("b_camera_drag"):
		camera_drag = get_viewport().get_mouse_position()
	if Input.is_action_pressed("b_camera_drag"):
		camera_movement.x += (get_viewport().get_mouse_position().x-camera_drag.x) * sensibility
		camera_movement.z += (get_viewport().get_mouse_position().y-camera_drag.y) * sensibility
	position += camera_movement
	camera_movement = lerp(camera_movement,Vector3.ZERO,0.2)
	if Input.is_action_just_pressed("b_rotate_camera_left"):
	if Input.is_action_just_pressed("b_rotate_camera_right"):

And that’s it. If you can, PLEASE, help me, i’m so lost. Ah, and happy new year.

1 Like

You can apply your camera’s y rotation to the movement vector, around a given axis, using Vector3.Rotated():

position += camera_movement.rotated(Vector3.UP, rotation.y)
1 Like