Hello,
How do I raycast from a cursor, to determine where it hits, on a 3D world?
Thank you ![]()
To convert mouse position on screen to a 3D position at a defined distance :
Just be sure that the z value from the Vector3 is the distance from the camera and not an absolute z position in the World.
To actually get the 3D position where the mouse is using colliders :
then…
You may also find the code example in this thread useful.
Hello, thank you Krobill and andeeee (checking, yup, got all 4 e’s in there lol) … Your replies were all very helpful! ![]()
I got a ray from mouse position onto the screen now, using the following code:
function OnGUI()
{
var e : Event = Event.current;
var ray : Ray = camera.ScreenPointToRay (Vector3(e.mousePosition.x,Screen.height-e.mousePosition.y,0));
Debug.DrawRay (ray.origin, ray.direction * 5000, Color.yellow);
}
The following image shows the result: (the red dot is where the mouse is)
Now, i was wondering how to get the position of where this ray hits? Thank you!
Can anyone please tell me how to get the position of where the ray hits the plane? Thank you
hit.point