I have been trying to make a cross hair for my game and I have been looking in the forums but I've just found how to make a crosshair for a normal fps, I want the crosshair move according to the position where a tank is shooting, not the camera.
can you please point me in the right direction.
Imma make a video in case you need more info to understand my problem.
Have you tried the crosshair script in the FPS tutorial? http://forum.unity3d.com//viewtopic....ight=crosshair
If you are looking at using a GUI based on the position of an object perhaps something like Camera.WorldToScreenPoint would be worth checking out.
Game Programmer/Technical Artist http://michaelhubbard.ca
thx for the reply.
I have already checked the fps tutorial, like I said I need the crosshair to move, not the camera...
I'll check the Camera.WorldToScreenPoint out and see what I can do with it.
thx again and more help would be appreciated.
If you explain your desired implementation in more detail, you might get some aditional ideas.
This is really dependent on what you want the crosshair to follow. The post above talks about following the mouse. If, however, your tank can only shoot the direction the tank or turret is facing, another implementation would be to determine the forward vector from the tank or turret (have a look at Vector3, the Vector3.forward property, etc) and then position the crosshair at a range along that vector. Different solutions to different designs...
Hi, I've the same problem.... for example....Star Trooper, fire missile - How to create crosshair which is following vector for fired missile. I've absolutely no idea how to do that or where to implement.
i have the same problem. i have been trying to program a crosshair that follows the mouse because my game makes sure that we click the object to shoot it so i stuck my own script on the enemy so i need a mouse-following crosshair.
Im not too sure on how to exactly implement it in Unity, but my best guess would be having the crosshair as a GUITexture
You would need the position of your mouse in terms of pixels (since GUI in unity works on a pixel basis)
Then all that would be left to do would be to center your GUITexture on the mouse's position each frame, which can be done in the Update() function as long as you have a reference to your GUITexture.
Hope it helps
If you need to position the crosshair with the mouse, then you should check out this thread which shows how to send out a raycast from the camera at the mouse's position. If the tank's turret is controlled by direct rotation and elevation then you should firstly use a raycast in the direction of the gun to see what it is pointing at. Then, you can use Camera.WorldToScreenPoint to convert the hit point of the raycast to a position on the screen:-
I'm wired to the world... that's how I... know... everything...