I am trying to figure out how to do a unit conversion between screen and world.

For example. A player drags their finger 20 screen units, how many units in world space would that be?

I’m not looking for Camera.main.ScreenToWorldPoint. but how to find the unit conversion.

EDIT:

I wanted to add why I need the units… The Input.touches provides a delta position, but it’s in screen space. I need to use this but to move something in world space. The Camera is moving, so the Camera.main.ScreenToWorldPoint is not going to work.

This can give you a conversion, although it’s not the same as camera.ScreenToWorldPoint.

Vector2 test = Random.insideUnitCircle * Screen.height;
float height;
if (camera.orthographic)
// Size is half of the height of the screen
height = camera.orthographicSize;
else
// Since units depends on how far the camera is to the plane that you are displaying on, trig becomes necessary
// As you can imagine, this will be really annoying if your camera or your plane is rotating
// I assume here that the plane is at origin and normal points to camera
height = Mathf.Tan (camera.fieldOfView * 0.5f) * Vector3.Magnitude (camera.transform.position);
// Both ortho and perspective cameras calculate width using height
float width = height * camera.aspect;
// First convert to a box with coordinates (-0.5,-0.5) to (0.5,0.5)
// Then scale to world units
Vector3 testPos = new Vector3 (width * (test.x / Screen.width - 0.5f), height * (test.y / Screen.width - 0.5f), 0);

Or something like that. Is there a particular reason ScreenToWorldPoint isn’t what your looking for?

You could in theory do the math and figure it out - but unless you have a specific reason to not use ScreenToWorldPoint it would be a waste of effort. The world point will depend on a number of factors including camera angle, position and projection that unless you have a fixed camera would change over time.

Basically:

At frame 0: 20 Screen Units may equal 100 World Space units

At frame 1: 20 Screen Units may equal 50 World Space units

At frame 2: 20 Screen Units may equal 1000196 Worlds Space units

This would be fairly simple to accomplish. First you need to look at Camera.ScreenPointToRay(). On the start of the drag you will use Camera.ScreenPointToRay() and save the hit point, and do the same at the end on the drag. You can then use Vector3.Distance() to find the distance between the two points.