So I need to know if there is any function that allows me to know in which direction my object is pointing. My intention in knowing this is to know where:
Also please remember that this works in a 3D environment with no gravity and no "floor" (space), and C# code would be pleasantly preferable.
Thank you very much for the answers =)
asked Dec 30 '11 at 08:43 PM
You could use the object's transform.forward vector: it will always point in the local +Z direction:
// get the point "distance" units ahead the weapon: Vector3 aimPos = transform.position + transform.forward * distance; // convert it to screen coordinates: Vector3 chPos = Camera.main.WorldToScreenPoint(aimPos);
The screen coordinates are returned in chPos.x and chPos.y. If you're going to use GUI.DrawTexture, remember that the GUI y axis runs upside down, thus you should use Screen.height-chPos.y to get the correct GUI y coordinate (chPos.x is ok).