Is there a way to get mouse position in 3D space at a given y-value?

I’ve got one solution to this problem by performing a raycast on a floor plane set at Y = 0 like so:

RaycastHit hit;
if(floor.Raycast(Camera.mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 100))
		{
			Vector3 hitPos = hit.point;
		}

but I’m wondering if there’s a more efficient way of doing it without a raycast or a plane if I can specify Y as a constant? This may be the best solution out there, but I’m curious if anyone has a better one before I call it.

Thanks!

A slightly cheaper raycast would be against a Plane(assuming that currently floor is a collider).

Example:

Plane plane = new Plane(Vector3.up,0);

float dist;
Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
if (plane.Raycast(ray, out dist))
{
  Vector3 point = ray.GetPoint(dist);
}

You could basically just drop the raycast:

Camera.main.ScreenToWorldPoint(Input.mousePosition)

but if you are using a downward-pointing camera, as it sounds, you will probably need to swap y and z coordinates… since “z” is the distance from the camera, i.e.:

var myTempPoint : Vector3 = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var myWorldPoint : Vector3 = new Vector3(myTempPoint.x,myYConstant,myTempPoint.y);