Mobile(Android): ScreenToWorldPoint works with Orthographic Camera, fails with Perspective Camera

Goal:
Game where player is falling down but is moving on the x axis by following the gamer’s finger (follows only press one)

Problem:
When in Perspective mode there is simply no effect. I have tries, changing the z value in touchpos but it did not help. Also the movement functions only happen when there is a touch, and only touch 1 is followed. There is no errors.

Solutions to similar problems on this and other forums did not help and the manual provides almost no information about the function in question.

Here is my code:
public class PlayerMovment : MonoBehaviour {

Vector3 camPos;
Vector3 thisPos;

Vector3 touchpos;

Quaternion rot;
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
    //Camera Control
    camPos = Camera.main.transform.position;
    thisPos = this.gameObject.transform.position;

    Camera.main.transform.position = new Vector3(camPos.x, thisPos.y-1, camPos.z);
    if (Input.touchCount > 0)
    {
        //Control Position of Player With Touch
        //retrieves touch 0, and sets it's position information to touchpos
        Touch myTouch = Input.GetTouch(0);
        touchpos = myTouch.position;

        //Projects the touch position into a point and than ignores z and y (world touch position saved to pos)
        var pos = Camera.main.ScreenToWorldPoint(touchpos);
        pos.z = transform.position.z;
        pos.y = transform.position.y;

        //Checks if touch is out of bounds, pushes inbounds if so
        if (pos.x > 3)
        {
            pos.x = 3;
        }
        else if (pos.x < -3)
        {
            pos.x = -3;
        }

        //sets the position of the cube to the mapped point
        transform.position = pos;
    }
    //prevents rotation
    rot.x = 0;
    rot.y = 0;
    rot.x = 0;

    transform.rotation = rot;
}

}

ScreenToWorldPoint takes a Vector3 as input, not a Vector2. A Vector2 can be implicitly converted into a Vector3, but the “z” coordinate will be set to “0”. The z coordinate specifies the distance from the camera origin in worldspace. Since an orthographic camera has a parallel projection an input position at a distance of 0 works as it should. However on a perspective camera all viewport lines meet at the camera origin. So at a distance of 0 all points on the screen will map to a single point which is the camera origin.

As solution you can simply pass a positive distance as z component

Touch myTouch = Input.GetTouch(0);
touchpos = myTouch.position;
touchpos.z = 5;
var pos = Camera.main.ScreenToWorldPoint(touchpos);

Though it may depend on what you want to achieve. While the z-distance doesn’t really matter much for the projected position, when using a perspective camera different distances will result in different positions on x and y due to perspective projection.