Does anyone know how to auto scale a model for the player’s screen size? I would like to use models instead of viewports (cuz they have bad fidelity) for when the player opens a loot crate or something but the models don’t scale like UI. What is the math behind it and is there any info?
This is my example:
you can see how the models clip out of the screen. Its not that players will change their display size during the game but rather on different devices the screen sizes will be different.
Cameras have a ViewportSize property that you can use to figure out the size of the player’s device’s display’s safe area. I would use it to figure out the height of the player’s screen and make your models change their size based on that.
As for changing the size of the models, there isn’t really a clean conversion between the dimensions of a screen and studs. The best I can think of is to just find an equation that makes your models the size you want on your screen in relation to the screen dimensions. A few ways I would begin to tackle this would be to make one of the dimensions of the model to be 1 stud while making sure the entire model stays proportionally correct, like below:
Obviously, the 0.9 and 2 stud edges aren’t necessarily those sizes. In fact, with the models you’ve got, I suspect that all sides would be 1 stud, since they look like cubes.
Once you have those models scaled down to a unit size, you can multiply all dimensions by the screen dimension. You’ll probably have to also adjust the screen dimension number using more math until the model is the size you want. Just make sure that that result doesn’t end up becoming a decimal, or you’ll get a model that shrinks.