0 votes

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 moveandslide() function wich is a KinematicBody node..
I really need the node to stay spacial and driven by the mouseMotion

Help pls :c

Godot version 3.1
in Engine by (20 points)
edited by

1 Answer

0 votes

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)


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.

by (334 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.