1

screenshot

Hi, Im trying to make an HTC Vive app. I wanted to make a canvas - world space with 3d objects to be on top of everything. And so i followed this answer. https://answers.unity.com/answers/887498/view.html .. It works perfectly.

Then I made the canvas be a child of the camera so that the canvas moves as the camera moves. Then I adjusted the Position Z of the canvas so that it would be in front of the camera.

The problem I have is, I want to use the controller to raycast on the 3d object in the canvas. I already have the script for it to be detected. So the canvas is set to UI layer as instructed on the link above. For it to be raycasted, I have to pass the LayerMask as parameter to Raycast() function.

However, see the png file, I have to estimate the distance of the canvas for it to be hit. In the screenshot, the blue cube is the 3D object in the canvas. the violet line, is the laser pointer and it would only appear if there is a hit. In order for the violet laser to appear, I had to estimate where the blue cube is. If i directly point to the cube, raycast wont hit.

Sorry if my question is unclear. I am having a hard time finding the right terms to explain my problem. Thank you.

  • I'm not sure I follow, "I have to estimate the distance of the canvas for it to be hit" why can't you just make it super long? "If i directly point to the cube, raycast wont hit.", Do you mean if the camera's looking right at it? Typical way to solve that is to translate the 2d midpoint of your viewport to a 3d world space look at pos, push that pos away and then cast to it from the camera pos. – George Nov 08 '17 at 08:08
  • - "I have to estimate the distance of the canvas for it to be hit" why can't you just make it super long? - the raycast distance i've already set to very long 9999. what i meant by "estimate the distance" is .. I have to point the controller to the very back, far away. because that is where the real cube is. Im not really experienced with unity 3d which i why my description isnt too well.. – user7888262 Nov 08 '17 at 08:18
  • - "If i directly point to the cube, raycast wont hit.", Do you mean if the camera's looking right at it? - I meant, if i use the controller to directly point to the cube, it wont hit.. if u could see again the screenshot i attached, I had to point the controller to the back of the cube ... – user7888262 Nov 08 '17 at 08:18
  • It's not obvious to me what you mean by "controller". – George Nov 08 '17 at 08:22
  • if i pointed the controller to the center of the cube, it doesnt hit..sad la – user7888262 Nov 08 '17 at 08:22
  • im using HTC vive controller for VR – user7888262 Nov 08 '17 at 08:22
  • Right so the problem is not with the raycast but the fact you can't tell where you're casting to until you've hit the box? – George Nov 08 '17 at 08:27
  • It could be, im really not sure.. thanks for the idea.. i really dont know what to do next.. ps. i'd be leaving now, so i would be able to see ur further replies by tomorrow.. thanks – user7888262 Nov 08 '17 at 08:29

0 Answers0