+1 vote

Is there a way to do toLocal() without using node, but instead calculate it using basis as the direction? Or just using anything other than node. I don't want to create a node to do toLocal(). It's kind of not efficient.

Godot version 4.0
in Engine by (21 points)

1 Answer

+1 vote
Best answer

Sure! You can check out the implementation of how to_local() works and recreate it in any other script.

func to_local(global_transform: Transform3D, global_position: Vector3) -> Vector3:
    var xform := global_transform.affine_inverse()
    return Vector3(
        xform.basis[0].dot(global_position) + xform.origin.x,
        xform.basis[1].dot(global_position) + xform.origin.y,
        xform.basis[2].dot(global_position) + xform.origin.z
by (1,611 points)
selected by

Thanks for the answer. I will try it later.

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.