Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
gabriead's avatar
gabriead
Honored Guest
11 years ago

Crosshair not displayed on Rift

Hi there,

i am pretty new to Unity and the rift. I would like to set up a crosshair so I used the following code, and added the script
to the OVRPlayerController:

Rect crosshairRect;
Texture crosshairTexture;
float crosshairSize;

// Use this for initialization
void Start () {

crosshairTexture=Resources.Load("Textures/Fadenkreuz2") as Texture;
crosshairSize = Screen.width * 0.1f;
crosshairRect = new Rect (Screen.width/2-crosshairSize/2, Screen.height/2-crosshairSize/2,
crosshairSize,crosshairSize);
}


void OnGUI()
{

GUI.DrawTexture (crosshairRect, crosshairTexture);
Debug.Log ("Building Crosshai");
}


The crosshair is displayed when I use a "normal" player camera.
But it is not displayed if I add the script to the OVRPlayerController.Any suggestions?

Thanks a lot!

Adrian

8 Replies

Replies have been turned off for this discussion
  • badgeir's avatar
    badgeir
    Honored Guest
    I think the problem is that you are drawing your crosshair in the middle of your screen. This will not be visible inside the rift, as the middle of your screen is hidden between the eyes. Done this way, your crosshair will be uncomfortably placed without depth in front of your eyes, which i doubt is the purpouse. I suggest rather making a transparent plane some distance in front of your ovrplayer, and adding your texture to this. This way the crosshair will have depth and be visible to both eyes (cameras).
  • I'd have to agree with badgeir, i tried something similar to your code initially and ran into a bunch of issues related to depth and convergence between the two images. I ended up creating an Ngui sprite and attaching it as a child of the left camera, from there it was easy to adjust properly while running the application
  • Thanks a lot for the super quick replies, creating a plane and adding it as a left child to the left camera fixed the problem!
  • Another question that is not directly linked to the crosshair but just occured.
    What functions from the API do I use to detect certain objects in the scene that the player is currently looking at?
    For instance if the player is looking at items on a table?

    Thanks a lot in advance!
  • @gabriead: I believe for that you can cast a ray from in-between the two cameras and see if it hit anything.
  • badgeir's avatar
    badgeir
    Honored Guest
    As cyber mentioned, look into Raycast. A good thing to do is probably taging the items you wish to let the player "look at" by using the "tag" pulldown menu in the inspector (you can create a new tag, e.g. "Lookable", and tag the lookable items with this. Then check if the tag of the object hit by your Raycast == "Lookable", and if so, do what you want to do to the object. (E.g. Change color or whatever). You should find examples of this online, i know i got it from an fps shooter tutorial.
  • I haven't tried it so far but sounds like a very good approach. Is it possible to use GUIText with the rift? It doesn't display any text, so I am using a plane with a texture again. What is an elegant way of working with text with the rift?
  • badgeir's avatar
    badgeir
    Honored Guest
    If you have pro version (which i guess you have since you're using the rift), you can use "3D Text" if you only want to display text: http://docs.unity3d.com/Manual/class-TextMesh.html . If you want other GUI elements, you can look into using RenderTexture to render GUI elements onto the texture of your plane. I'm unfamiliar with this myself, but it should put you on the right track (I think).