📜 ⬆️ ⬇️

Game development based on physical simulation (for realistic destructible game world)

In the first post about this game, I talked about the technical difficulties that had to be overcome. The second post you are reading now is easier to read. Here I will illustrate with gifs the whole way of building a physical model and briefly describe each step.

From the creation of a new project in Unity to the publication of the beta version in Steam, 10 months have passed. 90% of the time was spent on creating, optimizing and licking the physical model, the rest was on the gameplay.

The goal was to create a completely physical world. But the approach implemented in Red Faction seemed too cumbersome and not too realistic. In that game, the explosion meshes were broken into pieces, on which the physical colliders were pulled. I decided not to suffer with the raw materials and many special cases of destruction, but to make a simple system that works in all cases.
')
I made everything from interacting particles: land, buildings, tanks of players, enemies, shells and bonuses - everything. The interaction between particles implemented on the video card, since for parallel computing it is 50-100 times more productive than the processor.

The matter that came out of the particles looked strange at first, and resembled either a liquid or a gas:

image

And for the game it was necessary to have something strong, able to keep the shape. Having tried different ways of interacting particles, I found that the strength of Lennard-Jones gives the strongest substance. It turned out something like semolina. For experiments, I added explosions on the mouse click.

image

The particles already have a temperature, and matter changes its properties, melted by the heat of explosions. Matter itself holds volume, particles tend to form a hexagonal lattice. A small amount of viscosity (in addition to Lennard-Jones strength) provides better stability of matter.

The problem with stability is this. The discreteness of the model limits the magnitude of the interaction force between the particles, since at high speed the particles may become too close in one step, ignoring the steepest (twelfth) curve of growth of the repulsive force. This will give them a tremendous acceleration, which will make the new unnatural rapprochement even more likely. The law of conservation of energy is broken, matter explodes. And viscosity allows to weaken this effect.

When matter began to behave more or less satisfactorily, I collected a tank from the particles and made control for it: data on the keys pressed by the player are transferred to the video memory at every step of the calculations, and this data is used to control the rotation of the wheels and the inclination of the gun:

image

Interacting with the physically realistic world was fascinating, I was inspired. The game developed exactly in the direction in which I wanted.

Then I added a module for constructing the level of a picture: the pixels were read, and physical particles were created in their place. In addition, the matter "charred", blackening from prolonged exposure to high temperature.

At this stage, the imperfection of the physical model was revealed. Stone columns behaved like jelly:

image

We had to sacrifice performance, reduce the discretization step, and thereby increase the interaction force between particles, without the risk of instability. Matter has become more solid, and I have created several different physical materials: stone, metal, snow, sand, earth, ice, jelly, etc. Each material was slightly different from the others, the sand was loose, the stone was strong, the metal was strong and flexible, and the jelly was flexible and brittle. The tree burns and turns into ashes, and the ice is strong, but it melts easily.

Then I created several types of flying saucers from the same particles, and still there, in the shader code running on the video card, I wrote the control system for the enemies. They aim well, dodge each other, and use different combat tactics.

It turned out pretty similar to a computer game in the traditional sense:

image

On this gif, you can see that I used a new entity - a kind of bone that defines the distance between particles. They are also muscles, since they have a characteristic stiffness and a changeable length in time. So it became possible to strengthen tall buildings and make mobile platforms on levels.

In addition, I created a universal weapon description system, which allowed us to describe a wide range of means of destruction, simply stringing some unified effects on others, creating chains of events. Machine guns, flamethrowers, projectiles scattered in flight, multipath suns of thermonuclear explosions, fans of lightning, love guns and a whole bunch of power modifiers of matter appeared.

And I also created bonus items so that you can pick up ammo, boost your tank or influence the level on the button-event principle. For example, here you can see what happens when a player picks up a key:

image

You can also notice the similarity of the interface with stripes of health and other characteristics of the character tank, and with a list of available weapons.

It became possible to publish the game, I spent a week filling out various forms on Steam, waiting for the results of the test, designing the page and making a trailer and screenshots.

Greenlight was completed by that moment, because as I was ready I published gifs on reddit, evoking stable interest by an unusual approach to building peace.

Finally, the game came out in early access, here is the trailer:



(The music is from the techno-opera of Victor Argonov “2032”. Not very suitable, but exciting).

Summarizing the experience of development: the experiment showed that deep penetration of physics into the gameplay is technically feasible, but it is not yet very clear how to use it most for the gameplay. We still need to figure out what unique game features follow from the physical world. I am currently working on a campaign for one player, in which I try to use unusual ways of interacting with the world, I am doing a kind of hybrid of “Lemmings” and a platformer-shooter. In Lemmings, one had to dig a lot, blow up and build, and in a shooter - shoot. Here, let's see what a hybrid I get. I hope the players will prompt. At the moment, in the published game, only the battle mode is available, imitating the game Scorched Earth.

The purpose of this publication is to share the results of this experiment with fellow developers. Perhaps someone will be interested and want to give more space to physics in their game too. In the comments, they will certainly ask about the page in Steam, so I will immediately indicate it .

Source: https://habr.com/ru/post/328284/


All Articles