Post

October Developer Update

The battle for good physics, part 2

Hello, friends!

This month I made a great progress developing the game. I spent it almost exclusively on physics, implementing things I mentioned it the previous update. And everything worked out almost exactly as I planned and I did even more than I could have imagined. So, without further ado, let’s talk about it.

Some rockets were hurt while preparing this update

Rocket physics

The only good way to support timeline and time rewind is by representing the spacecraft with one physics body. But since the spacecraft is made by player and consist from different parts with different shapes and masses, I needed a good way to account for it in the simulation. Otherwise, you will immediately feel, that the physics is not correct. I solved it by calculating the forces that affect every part individually and then applying them at the right positions of rocket’s body. So, if you will not balance your rocket right, and there is not enough auto stabilization force, it will eventually start flipping to the side with greater mass.

Aerodynamics

I used USSA equations for the atmosphere model. Since Earth and Solar system are in real scale in the game, the equations was not modified in any way. The only difference is that Earth atmosphere in the game ends at 110 km, where the pressure is so low that it can be neglected. The surface area and dimensionless drag coefficient are pre calculated for each part, which means that the shape of spacecraft will affect it flight characteristics. The approximations I used for calculating drag forces give decent results and have a good performance. But I am open for the better drag models in the future.

Collisions

This was the hard one. All collisions are handled by PhysX. And there is always a tradeoff between accuracy and performance. If the collisions were solved even a bit incorrectly, spacecraft will be immediately launched with 10x speed of light into abyss, because bodies has huge masses and moving with the high speed in the simulation. One small error and the whole experience will be ruined. But if you increase accuracy too high you will receive a poor performance and angry players. While I found a decent settings for collision solver, I will expose some of them in the game settings, so everyone will have chance to tune the game to their computer capabilities. Here are some funny gifs before I tuned the PhysX and fixed tons of bugs.

A simple collision with the ground threw a ten-ton rocket, as it was made of plastic

Here collision between two parts of rocket send both to the orbit of Pluto

What else?

For now the water physics is missing. I wasn’t be able to quickly find the good algorithm for that. I could use the same drag model as for atmosphere, but with higher density, but I don’t think this is the only and right solution. So I will continue investigate this topic after release. For now there are two options: every spacecraft will immediately explode on the contact with water. Or it will just ignore the water and fall though it. I like the first option more, because it destroys immersion to a lesser extent.

Also I didn’t implemented wings yet, but I will do if I will have time for it.

Not only physics

When I got tired of fixing physics, I switched off to another area of the game. The first one was stars. Initially I used simple texture for it. It was huge (almost 8 Mb with the resolution of 8192 x 4096), but even with that stars looked blurry. Also all of them had the same color which is far from reality.

Old stars

So I implemented own starfield system using the real world star database, which includes more than 110k stars. Every star now uses a color, brightness and position from that database. Even with 65k stars all the data occupied only 2Mb of memory, but you usually don’t need this many. You can see about 6000 stars with your naked eyes. And again I will expose starfield settings, so you can change the stars count. maximum brightness and exposure how you would like. The only thing I am missing now is the Milky Way, But I will make it sooner or later too.

New stars. It is better to compare both images in full-size in the browser

The second one is the orbit rendering. Initially I used builtin Line Renderer, but it was not good, when the orbit was far enough from the camera.

Well, time to implement custom orbit renderer!

It is better to compare full-size images here too

At the end of this month I felt like I created my own game engine for the flight simulation. Almost everything is custom: planet generation, orbital mechanics, drag and gravity, starfield and even my own version of the line renderer. Funny enough, I got around 80 FPS in the flight on my computer (i5-4590 and GeForce 970), where so many different calculations happens. And only 55 FPS in the spaceport, where nothing complicated is going on, just a bunch of objects and light sources.

It’s time to finish this update. I will leave you a gif where you can see the result of all work done in this month. It looks so simple, right? But it was not easy no get there.

Note: the gif was recorded on 5x time warp

This post is licensed under CC BY 4.0 by the author.

Популярные теги