Convert raycast intersect result into world position
Asked Answered
P

2

0

Hello.
I am trying to convert a raycast intersected result's " position" to world space coordinates.
Though I can't seem to find a built-in function for that in Vector3 class or World3d class in docs. The result returned by raycast test is in like -2 to 2 range, which seemed to be the local space x y z between colliders.

Hence the question: so how you convert a local space result into world space coordinates?

Thanks.

Papistry answered 8/11, 2022 at 18:50 Comment(0)
C
0

You would use the function xform or xform_inv from the Transform class.

I'm not sure if you can do directly from local to global space (maybe with global_transform, I haven't tried). But for going one level up you would do.

var next_pos = your_node.transform.xform_inv(local_pos)
Craggy answered 8/11, 2022 at 21:17 Comment(0)
P
0

Thanks I will see if that's what I need.

Edit: It turns out to be a bug in my position change function, sorry for the confusion.
The result.position is in 'world space' if space_state is set to world3d.direct_space_state

Papistry answered 8/11, 2022 at 23:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.