Is it possible to set a GameObjects moving speed depending on the size of the game window/screen resolution?
To be more specific I have a GameObject with a script attached to it. The script moves the GameObject with transform.translate. It always moves the same speed but I don't want that. I want it to take the same amount of time to go from the bottom of the game window to the top of the game window no matter the size of the game window. Currently if the game window is large the GameObject appears to be moving slowly and if the game window is small the GameObject appears to be moving more quickly.
Anything is possible but it sounds strange that you'd want to go about fixing the issue that way. If you change the objects speed, then it will be moving slower in proportion to its own size and it will again look and feel pretty different on different resolutions.
How are you moving the object? Is it a UI object or something in world space? Orthographic or perspective camera?
Usually all you need to do is change your camera's FOV or orthographicSize based on the screen aspect ratio: that way your screen height will always be x units in world space, your object will stay the same size in relation to its speed and screen size and thus it will take the same amount of time for it to travel x units.
Thanks for the response. Yeah it's an UI element I'm trying to move. It's actually the credits text which goes from the bottom of the screen and up. Because it's part of a canvas and I've set the canvas to scale with screen size the text is the appropriate size. I added a script to the UI text GameObject which makes the text move, it used transform.translate to do so. The speed is the same no matter the size of the screen/game window. This makes it feel like the text is moving faster or slower than what I want it too. I could most likely use math to make it go the appropriate speed if only I could get the size of the game windows specifically. I tried using the Screen class but either I don't understand how to use it properly or it takes the width and height of the screen itself, not the game window.
Answer by TheShadyColombian · Jul 22, 2016 at 06:23 PM
use Screen.currentResolution
to get the screen resolution in a sort of weird vector2 format ( so Screen.currentResolution.height
for the height instead of Screen.currentResolution.y
. Weird, I know);
Ah yes thank you very much. This seems to work. I already tried using the Screen class but I didn't know about Screen.currentResolution. Either way now it works as intended :)