Pan camera according to it's orientation

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

I want to pan my camera according to the direction it looks.

My Camera node is child of a Spatial node (camHolder - self in this code). So rotation and movement is on the Spatial instead of the Camera itself.

With the following code it works right if I don’t rotate the camHolder, otherwise direction of movement is messed up.

var dragging = true #Set at another place in code
var panSensitivity = 0.03

func _input(event):
    if event is InputEventMouseMotion and dragging:
        self.transform.origin = Vector3(self.transform.origin.x - (event.relative.x * panSensitivity), 0, self.transform.origin.z - (event.relative.y * panSensitivity))

So how could I make the panning always correspond to the movement of the mouse?