Pookie
Pookie

Reputation: 1279

Scaling issues with Unity

I am trying to get the starting paddle (I am creating pong) to be at the left most of the screen at all times. I am having trouble coming up with a good formula for doing this. My camera size is 5, it is centered at (0,0). The paddle should be at approximately -6.5 for the x-coordinate. Here, in the script for the paddle, is how I am trying to do this

    //renderer is the SpriteRenderer
    xPos = -Camera.main.orthographicSize - 
        (renderer.sprite.textureRect.width/ renderer.sprite.pixelsPerUnit);

However this results in this (the left paddle is here the code is being applied):

enter image description here

So, the right paddle is essential being placed at the very left - the width of the image. However, some of the paddle image is cut off. I can't seem to figure out why and I have checked everywhere. Any help would be extremely appreciated and noticed.

Upvotes: 0

Views: 48

Answers (1)

ORParga
ORParga

Reputation: 390

I think your problem is related to the calculation of the width of the screen.

Unity uses Camera.main.orthographicSize to calculate the screen's height and then calculates the width depending on the screen proportions. Try to calcule the width in this way:

width= Camera.main.orthographicSize * Camera.main.aspect;

Upvotes: 1

Related Questions