Move a spacial node based on its rotation

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

I’ve got a spacial node, with a camera as child of it

its Y rotation changes based on mouseMotion.x input when rightclick is pressed

var acceleration = 10
var hRotation

func _physics_process(delta):

    if m2_down:
    	hRotation += -mouseMotion.x

    rotation_degrees.y = lerp(rotation_degrees.y, hRotation, delta * acceleration)

Works perfectly
But now i need to transform the Node along its locals, when leftclick is pressed, based of mouseMotion aswell

if m1_down:
	destination.x += mouseMotion.x
	destination.z += mouseMotion.y

global_transform.origin = lerp(transform.origin, destination, acceleration * delta)

The code works untill the Node is rotated, its still moving on the global directions

I’ve found a solution online, using the move_and_slide() function wich is a KinematicBody node…
I really need the node to stay spacial and driven by the mouseMotion

Help pls :c

:bust_in_silhouette: Reply From: stormreaver

I suspect the root of your issue is the mixing of global and local transforms. Perhaps change

global_transform.origin = lerp(transform.origin, destination, acceleration * delta)

to

global_transform.origin = to_global(lerp(transform.origin, destination, acceleration * delta))

Even if this code doesn’t fix the issue, the problem is most certainly rooted in the mixing of global and local transforms.