Topic was automatically imported from the old Question2Answer platform.
Asked By
Alex Pires
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.
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.