ScreenToWorldPoint fixed height

Hi! I am trying to move a object with touch input, it works flawlessly and i it looks like it is exactly where i want it to be, but it is not. I want the object to be fixed in the Y-axis, and only move on the X and Z axis.
I am using a orthographic camera that is rotated (X:45)(Y:30)

This is basically the code i am using;

if (Input.touchCount == 1) {
	transform.position = new Vector3 (Camera.main.ScreenToWorldPoint (Input.mousePosition));
}

The object i am moving is the white cube. Ignore the text on the side, it´s just for debugging on my phone :slight_smile:

Camera perspective:


The cube is selected and right above the camera icon.

Editor perspective:

As you can see, i want to move the object on the ground-plane, wheras a fixed Y position.
But the screenToWorldPoint function moves the Y pos. I have search everywhere and can´t seem to find a way to do this. Does anyone know how to do it?

I had to use Raycasting on a Plane.

This is the final code;

float groundYpoint = 0.525f;
Plane groundPlane = new Plane (Vector3.up, new Vector3(0f, groundYpoint, 0f));

if (Input.touchCount == 1) {
		Ray touchRay = Camera.main.ScreenPointToRay (Input.mousePosition);
		float rayDistance;

		if (groundPlane.Raycast (touchRay, out rayDistance)) {
			transform.position = touchRay.GetPoint (rayDistance);
		}
}

By using @bilelmnasse version, the only problem is that the object won’t appear where the user touches the screen. It might even be outside the camera view. But by using this raycasting method it works fine!