|
Hello there! 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 =)
(comments are locked)
|
|
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). Thank you very much for your answer. It works but there is still one problem: The Crosshair fails to accompany the object, often taking much time to put itself in front of it. My current code is this one:
Dec 30 '11 at 10:52 PM
JPB18
Oh wait, managed to make it work just like I wanted... Just had to parent the CrossHair object with the fighter :P Thank you very much! :D
Dec 30 '11 at 11:25 PM
JPB18
(comments are locked)
|
