- Home /
Raycast visual and moving text possition.
Hello Unity community,
We're a group of students finishing some volunteer assignment, about creating visual representations to younger math students. Currently we're creating an interactive mini game-program that at the end, will allow the user to navigate a point around in a 3 dimensional space, to understand certain things like Dist(p) formula, and geometric space easier. But we need some help!
The setup: We're using three planes, to represent the background of the geometric planes, and a point object inside the perimiter, I'd like to use something like raycast for:
(a) Project a visual line from the point in three directions, towards the planes.
(b) Extract the x,y,z coordinates from the point, and display at the point where the raycast collides with the plane, and move this point around as the point in space moves around.
Any help is greatly appreciated, and all coding contributions will be credited in the index of the entire teaching material.
Additional information:
Currently using a debug solution to draw the lines:
Debug.DrawLine (PointPosition.position,Vector3(PointPosition.position.x,PointPosition.position.y,0), Color.red); Debug.DrawLine (PointPosition.position,Vector3(PointPosition.position.x,0,PointPosition.position.z), Color.red); Debug.DrawLine (PointPosition.position,Vector3(0,PointPosition.position.y,PointPosition.position.z), Color.red);
But this is a gizmo, and won't show up in-game obviously, so need an effect to replace this, preferably a dotted line or normal line. Also for b) I think using text, I could update the location in the world, by the same way (x,y,z) with one always being 0, so that's solved too, just need the actual lines drawn, anyone?
Answer by whydoidoit · Sep 09, 2012 at 09:53 AM
You will need to use LineRenderer to draw your lines. It is probably not necessary to use a RayCast as you will know the distance from your point to your 3 planes so any calculation of your text position or lines will be taking the coordinate of the point and just replacing a dimension with the position of the respective plane.
To convert your plane coordinates in 3D to 2D positions for an OnGUI call to draw your text (for example) - you would use Camera.WorldToScreenPoint on Camera.main (the currently active camera). This will give you the pixel location of your impact points.
You can make dotted lines by using a transparent material and a suitable texture.