Hi.

I wanto to perform an action if the child of PathFollow change it's rotation in the y axis. I've tried to use statements under global*transform.origin and global*transform.basis without success.

Thank you in advance.

+1 vote

Best answer

I didn't try out PathFollow but I can tell you how to get the global y-angle for any spatial.

Also, I did some tutorial/text about 3D vector / transform operations:

https://godotdevelopers.org/forum/discussion/18480/godot-3d-vector-physics-chea

You should get an angle with this code:

`Vector2(global_transform.basis.z.x,global_transform.basis.z.z).angle_to(Vector2(0,-1))`

Explanation:

This gets the x and z components of the current direction vector of the global transforms z-axis.

So this basically is the 2D direction vector in the global X/Z plane.

(This will not work if the child is directly looking 90° up/down because the z-vector will then be looking up/down and therefore have a length() of 0 in the global X/Z plane.)

Then the angle to the global "forward" vector is calculated. This could as well be Vector2(0,1) if in your world +z is "forward". If you need degrees then you can use rad2deg.

- All categories
- Engine 28,057