Unity Community

Results 1 to 9 of 9

Thread: Crosshair

  1. Posts


    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.


  2. Location
    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

  3. Posts
    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.

  4. Location
    Arlington, VA
    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...

  5. Posts
    Thx for your help.

    here's a video of the tank, I still need to make the crosshair.


    I'll post the video of the tank with the crosshair later, I hope.

  6. Posts
    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.

  7. Location
    No one will know this i'm not a stupid Troll.
    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.

  8. Posts
    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

  9. Unity tech writer

    Blackpool, United Kingdom
    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:-
    2. if (Physics.Raycast(ray, hit)) {
    3.   var crosshairScreenPos = Camera.WorldToScreenPoint(hit.point);
    4. }
    You can then use the GUI system to position the crosshair texture at the position you have calculated. You should subtract half of the crosshair's pixel width and height from the screen position so that the centre of the texture is over the target point.
    I'm wired to the world... that's how I... know... everything...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts