Hover physics in Unity
Mars Commander makes use of semi-realistic hover physics that lead to a unique gameplay experience. For example, vehicles will bounce off cliffs and reach extreme heights if you speed up a hill and press the "jump" button at precisely the right moment. It's a pretty satisfying feeling.
The hover physics are made even more prominent because of the low gravity enivronment. Mars is only about half the size of Earth, but its gravity is just a third. Playing the game, you will notice this.
Technically, physics in Unity are usually best handled in FixedUpdate, which executes code 50 times per second. The effect is wholly indepent of Unity's framerate, meaning you'll get consistent results despite whatever else may be going on in your game. In Mars Commander, each vehicle updates its hover height in FixedUpdate using a complex and mostly realistic algorithm.
The basis of this algorithm was not something that we invented ourselves, as we got it from this excellent YouTube video:
Just like that video, we use Hooke's law to create our hover effect. This law of elasticity was discovered by the English scientist Robert Hook in 1660, and states that the displacement or size of a deformation is directly proportional to the deforming force or load. In practice, this means that every one of our vehicles has an ideal hover height that they will always strive towards. However, due to undulations in the terrain and other factors, such as incoming enemy projectiles, vehicles may deviate.
We tried implementing this effect in three dimensions, but this led to unexpected results, as units would always topple sooner or later. Thus, we limited the effect to one axis, meaning that only height mattered in our calculations. The effects wasn't completely realistic, but it was without a doubt the most fun solution we could devise.
Usually, graphics are the factor that limits a game's performance most. However, in the case of Mars Commander, we noticed that CPU calculation also had a significant impact. While this wasn't only due to realistic hover physics, they certainly played a part. This is why we opted for two different means of calculation, one for when the player is near and one for when he is not. This drastically improved the game's performance.
There is muchmore to be said about the topic of hover physics, as these have also had a major impact on our AI and its setup, for example. However, that will be a topic for another time.
Get Mars Commander
Mars Commander
First-person RTS with fully-controllable tanks, turrets, nukes, engineers, and more
Status | In development |
Author | Space Wizard |
Genre | Strategy, Shooter |
Tags | 3D, First-Person, Futuristic, Immersive, Physics, Real-Time, scifi, Singleplayer |
Languages | English |
Accessibility | Subtitles |
More posts
- Massive development update with new downloadable demoJun 27, 2023
- Mars Commander concept artMay 21, 2023
- An evil AI took over Mars (Mars Commander story)May 21, 2023
- Stellar Unity, sci-fi visuals on MarsJan 27, 2023
- Updated demo available nowJan 27, 2023
- Mars Commander is now playable from start to finishJan 21, 2023
- Mars Commander First Person RTS ScreenshotsJan 01, 2023
- Wishing everyone an explosive 2023 (screenshots included)Jan 01, 2023
- Mars Commander 3D shooter RTS trailerDec 22, 2022
- How to reduce code complexity and boost performance in UnityDec 21, 2022
Leave a comment
Log in with itch.io to leave a comment.