Screen resolution and aspect ratio

Hello,

i’m new to the Unity world. So… hello :o

I started to develop simple 2d game (with orthographic camera) where a player move a box a shoot to the enemy. In few hours i’ve done this.

Because in my mind i wanna develop a future game on OSX,Win,iOS and Android i started to build on Android device and only one things doesn’t work properly.

Issue : the player when goes out from the camera view, for example to the left, i respawn it on the other side. On OSX with 1280 x 800 resolution i calculated that the new position is 23f traslation from the center of the scene.

On Android with 800x480 resolution is different.

Solution (that doesn’t work) : if the translation is equal to 23 with 1280 x 800 , i guess that a proportion to 800x480 could work fine. Wrong! I’ve done myNewSpawnPos = Screen.currentResolution.width * 23.0f / 1280 .

How can i fix it ? Is involved the aspect ratio too ?

My goal is that the game will be resolution independent … -.-

really thanks to everyone!

its best to use norrmalized percentage values that take screen width and height into account for positioning objects viewed by an orthographic camera

Nice trick! I’ll try it! Thanks!

cool , just thought I should also mention its obviously not the only solution , you can also use scaled pixel values. I have both formulas in my class so I can choose either one depending on what Im doing. I cant post my full solution but here is the final condition for layout in the class once ive computed several things to give me some flexible options for texture pivot and where the layout starts and in what direction to measure , anyway xCord/yCord are in the range 0-1 in the if statement and should point you in the right direction

if(positionByPercentage){
			transform.position = new Vector3((-screenWidthHalf+(screenWidth*xCord)+textureXOffset),(screenHeightHalf-(screenHeight*yCord)+textureYOffset),positionZCache);
		}else{			
			transform.position = new Vector3((layoutFromXValue+(CoordXScaled*polarityForCoordX)+textureXOffset),(layoutFromYValue-(CoordYScaled*polarityForCoordY)+textureYOffset),positionZCache);			
		};