The question is most likely answered (comment voted up by OP but no response from them)
How to make object fall in the same amount of time no matter screen height?
I am developing a 2D Mobile game, and part of it requires an object to fall from the top of the screen to the bottom. I want the game to be equal among all screen heights, so how could I make my game object fall from the top of the screen to the bottom in the same amount of time no matter how tall a phone’s screen is?
Answer by Le-Pampelmuse · Nov 03, 2019 at 04:41 PM
Without having proper details about the specific mechanics involved in your game, I would suggest using a animation for the falling object.
Since animations run at set speeds, using their own frames per second settings, you could have either a million complicated keyframes per second or just 2 simple position keyframes per second, both would take one second to play.
That would, in my opinion, be the easiest way to ensure consistent fall time across all phones or screen resolutions without any calculations.
Answer by xxmariofer · Nov 04, 2019 at 03:12 PM
there are 2 options, what i tend to use is a script that uses a fixed height/width in all my games across all devices, or simply set both objects to be at the border of the screen, using the Screen.height parameter, and use the Vector3.lerp so that both objects reach the desired position in the desired time, if you need help with any of the solutions just ask me
I don't think any of those suggestions will solve the OP's stated problem:
How could I make my game object fall from the top of the screen to the bottom in the same amount of time no matter how tall a phone’s screen is?
It is still unclear if OP meant just the different screen resolutions of phones or the actual screen sizes. I interpreted it as the second option, hence why I suggested using an animation.
Since the OP has not responded to my comment, but actually did vote it up, I'm converting my comment to an answer and closing the question as accepted, since it seems that it solved their problem.
"the actual screen sizes" will allways depend on the screen resolutions. it is imposible my suggestions doesnt fix his issues, if you consider your answer to be right just because he upvoted is all fine (altough i cant see any upvote), but your answer is not a better solution than $$anonymous$$e and is imposible that my answer doesnt fix his question. you are suggesting using unity animations, and all animation engines use lerping for position transpolation.
Hi.
"the actual screen sizes" will allways depend on the screen resolutions.
That's incorrect. The real world screen size is completely independent from the Screen.height in pixels.
$$anonymous$$y Sony smartphone has a 4$$anonymous$$ screen height of 12 cm, it's Screen.height == 3,840
.
$$anonymous$$y Samsung FULL HD monitor has a screen height of 39.8 cm it's Screen.height == 1080
A gigantic screen on a baseball field might have an even lower resolution, but is 10 meters high.
but your answer is not a better solution than $$anonymous$$e...
That's a subjective opinion and completely fine.
..and is imposible that my answer doesnt fix his question
That's not really for you to decide, is it? ;)
if you consider your answer to be right just because he upvoted is all fine (altough i cant see any upvote)
You can very easily visit the OP's page and see their last activities. You can't see the upvote here because I initially posted it as a comment, because it was just a suggestion based on incomplete informations, and later converted it into an answer. As a comment, it had an upvote from the OP. Now that you mention it, that IS weird. Another bug in the Answers platform.
you are suggesting using unity animations, and all animation engines use lerping for position transpolation.
It might be that many animation implementations use inter-polating to smooth out between positions, but using Vector.Lerp
is discouraged for controlling general movement, unless in very special cases, because every since it existed, people using Unity constantly used it wrong and in connection with Time.deltatime. That's a failure prone and inaccurate way to move things.
I don't claim that you intended to suggest using it this way, but since you didn't eleborate any further in your answer, I chose to point out that the way it is commonly used, won't work here. $$anonymous$$aybe I should have added this paragraph to my initial comment on your answer to avoid confusion, sorry.
However, as I stated in my comment-turned-answer, using the animation system is just the easiest way (for the scope of the OP's application) without involving any additional calculations like coding. I did't claim it was the only way. ;)
Greetings.
Follow this Question
Related Questions
2D gameobjects only showing Sprite! 0 Answers
Select Object And Spawn it 1 Answer
My collider2D don't work 1 Answer
GameObject overlapping on random spawn 0 Answers
Assign GameObject OnMouseUp not through inspector -2D 1 Answer