Hi there!
I'm trying to create a camera follow behavior to my 3d game, but I'd like to have a mouse camera rotation as well.
For the camera follow, I'm using on a Camera3D node:

extends Camera3D
@export var lerp_speed = 3.0
@export var target: Node3D
@export var offset = Vector3.ZERO
func _physics_process(delta):
    var target_xform = target.global_transform.translated_local(offset)
    global_transform = global_transform.interpolate_with(target_xform, lerp_speed * delta)
    look_at(target.global_transform.origin, target.transform.basis.y)

And for the mouse camera rotation, I'm using on a Node3D (CameraPivot, parent of the Camera node):
extends Node3D

@export var mouse_sensitivity = 0.0015
func _input(event):
	if event is InputEventMouseMotion:
		rotation.x -= event.relative.y * mouse_sensitivity
		rotation_degrees.x = clamp(rotation_degrees.x, -90.0, 30.0)
		rotation.y -= event.relative.x * mouse_sensitivity

My tree:

However, it seems the camera rotation with the mouse doesn't work because it's overwritten by the camera follow code. Does anybony knows a solution to have both behaviors working together in a proper way?
Thanks in advance.

  • xyz replied to this.
  • fabianom Use local instead of global transform in camera code.

    fabianom Please put your code snippets inside ``` tags to format them properly.

    xyz It kinda worked, but the result was horrible. hahahahaha. I will try another camera approach for better results. Thanks anyway. 🙂

    • xyz replied to this.

      fabianom You may try using some logic that switches between the two depending on whether the mouse is engaged.