to_local() without using node.

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

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.

:bust_in_silhouette: Reply From: zhyrin

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
    )

Thanks for the answer. I will try it later.

PiCode | 2023-03-21 18:05