Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

"Scaling" without affecting physics?

Discussion in 'Editor & General Support' started by GuruGurra, Aug 17, 2020.

  1. GuruGurra

    GuruGurra

    Joined:
    Jan 18, 2018
    Posts:
    38
    I have a square "room" viewed from above with a perspective camera, and in this room objects can move around and bounce against colliders in the walls.

    How can I make this "room" look and behave the same way regardless of screen orientation and resolution? I want the square room to fill the screen width or height depending on which one is the smallest. I want the objects in the room to have the same size relative to the room regardless of resolution. I want the objects in the room to behave in the same way given the same force and rotation, i.e. gravity, mass, drag and so on must be exactly the same regardless of how the room is "scaled".

    What I'm aiming at is to have networked devices (Android) with potentially different resolutions and orientations to show exactly the same thing (speed, bounces, end position) when the same force and rotation is applied to an object (starting at the exact same position on all devices).

    Is this possible? If so - how?
     
  2. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Physics and rendering are completely different things.
     
    Vryken likes this.
  3. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    ^ This.
    Device resolution and orientation should have zero influence on the scale & physics operations on your GameObjects.
     
  4. GuruGurra

    GuruGurra

    Joined:
    Jan 18, 2018
    Posts:
    38
    OK, so what am I doing wrong? If I in the editor design my room to fit in landscape mode and then switch to portrait it will keep the same size and thus extend way outside of the available screen space. How should I resize the room to fit the new resolution without affecting physics?
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    You can't change the size of something without affecting physics. If the room changes shape it will change shape. Especially if you're trying to do a networked thing across different screen resolutions...

    The easiest solution will be to squish your camera viewport essentially without changing the actual physical size of the world to match some reference aspect ratio. This will mean that things might be distorted on different aspect ratios though. Spherical objects may look like ovals for example. Bounce angles may look funny on some devices.

    If, however, you accept that your view of the room will look different, everything else will naturally fall into place including relative sizes and velocities of all objects.