Log in or register to post comments

Object Ray

July 27, 2018 - 3:30am #1

Hey all,

I've been reading about and trying to fix this issue for too long now.  Time to ask for help.

I can easily ray from screen down to objects.  That works fine.  In fact all my googling takes me to solutions for raycasting from screen to objects.  I'm trying to do something much simpler.


Object A rays to Object B.


Object A is a sphere.  It has the script attached.

Object B is a cube that should become a child of Object A on Ray hit.

The method is called via a button press. (the "else" confirms the button works).  x is a simple bool to ensure the processes are swapped per press.

I made a prototype in 3D and it all worked fine.  Now I've attached it to an ImageTarget and I'm using the ARCamera, it no longer works.  I get no errors or warnings.  It's almost like the ray simply isn't happening. 

I'd really appreciate any help with this.  I've returned to this problem on and off for over a month, with no progress made.  If you want any other info feel free to ask.  Thanks in advance you lovely lovely people

<p>void GrabandDropTile()<br>
	    {       <br>
	        float maxPickingDistance = 100;<br>
	        //cast from selector to the tile below and child it ready for movement<br>
	        if (Physics.Raycast(transform.localPosition, Vector3.up, out hit, maxPickingDistance) && x == false)<br>
	            hit.transform.parent = selector_Control.transform;<br>
	            raytest.text = "test success" + hit.distance;<br>
	            raytest.text = " else test" + transform.localPosition;<br>
	        // re cast to the selected tile and return it to child of the Gameholder<br>
	        if (Physics.Raycast(transform.localPosition, -Vector3.up, out hit, maxPickingDistance) && x == true)<br>
	             hit.transform.parent = gameHolder.transform;<br>
	            print("Found an object - distance: " + hit.distance);<br>
<p>    }</p>

Object Ray

July 27, 2018 - 8:28am #2

Really hard to tell whats going on from your description.  Your script implies you have three game objects, are they all parented to the image target?  A screen shot of you Hierarchy might help.  When you test in the editor and view in the Scene view, are all the objects where you expect them to be?   What are the upload units you used on the image target?  If they are large then maybe the your expected distances between objects is changing from your working prototype when Vuforia kicks in and the ray isnt traveling far enough.  Have you actually drawn the ray to see it visually with:  https://docs.unity3d.com/ScriptReference/Debug.DrawRay.html


Log in or register to post comments