Android - Normalize touch position based on mobile screen size

Hello there,

What I am trying to do for the latest hours is to normalize the position I get from touch.position to make it work on multiple devices with different aspect ratios and resolutions.

The code I have (doesn’t work) is here:

function TouchYWorld (touch : Touch) {
    
    touch.position.y = (touch.position.y / Screen.height) * frustumHeight; //height is 320
    return touch.position.y;

}

However I get a warning that tells me assignment is temporary, which I can’t really explain why it happens.

I have also tried using a temporary value:

var temp = touch.position;
temp.x = (touch.position.x / Screen.width) * frustumWidth;
touch.position.x = temp.x;

You’re not suposed to change the original values from the “touch” variable.

Save the value to a new variable or return it directly:

function TouchYWorld (touch : Touch) {
    var y = (touch.position.y / Screen.height) * frustumHeight;
    return y;
}

function TouchYWorld (touch : Touch) {
    return (touch.position.y / Screen.height) * frustumHeight;
}