- Home /
how to get the absolute direction?
Hi (again...),
i creating side scroll games. my player can make a loop in the air and when he upside down he need to roll back. my problem is that i can't really know when he fly to the left or to the right. i use this to rotate the X axis:
transform.Rotate (-250f * Time.deltaTime,0 , 0);
i also tried to use transform.eulerAngles.x but none give me the real Angle between 0 to 360.
so, what should i use or any method to know where am i fly (right or left) will be great help!
thanks!
Answer by DaveA · Aug 24, 2013 at 07:05 PM
transform.forward is a vector that will always point in the direction your transform is facing. So if the Z axis of your character is aligned with the Z axis (think of it as the Z arrow points through his nose, or chest, or whateever, his 'forward' direction), transform.forward will tell you which way he's facing. Then if transform.forward.z >0 he's pointing right, if < 0 he's pointing left, assuming he 'faces' left or right and not into/out of the screen. And that x is left/right y is up/down.
this works like a charm! didn't know i can use transform.forward this way... thanks!!!!