0 votes

The problem is quite simple: i wanted to translate an object parented to another along the world axis. the translation vector must be transformed in parent space.

enter image description here

see video: https://peertube.mastodon.host/videos/watch/514e26ea-e7f4-43e1-b642-b00d464fe5dd

Here is how to do it:


extends Spatial

var init = null
func _ready():

func _process(delta):

    if init == null:
        init = $tester.transform.origin

    var diff = $tester.transform.origin - init

    # copying the full transform to p1
    $cub.transform = $p0.transform * $p0/p1.transform

    # extraction of the rotation matrix of p0
    var q = Quat()
    q.set_euler( $p0.transform.basis.get_euler() )
    var t = Transform(q)

    # creation of a temporary matrix containing 
    # the translation to apply
    var t2 = Transform()
    t2.origin = diff

    # important part: transformation of global matrix to 
    # local matrix of p0
    t2 = t2 * t.inverse()

    # we can now add the translation to the cube in p0 space
    $cub.translation += t2.origin
in Engine by (115 points)

I don't know much about this, but I'll try taking a crack at it.

Have you looked into the to_local() and to_global() functions of the Spatial class?

Nope... thanks for the tip :)
I needed to understand the way to use Transforms to reorient direction (i'm currently working on skeletons and bone poses)

Please log in or register to answer this question.

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.