How to get the rotation_degress.y of a child of PathFollow? [3D]

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


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.

:bust_in_silhouette: Reply From: wombatstampede

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:

You should get an angle with this code:

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.

Thank you very much.

Alex Pires | 2019-03-03 16:59