Game development based on physical simulation (for realistic destructibility of the 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 is easier to read. Here I will illustrate with gifs the whole way of building a physical model and briefly talk about each step.
10 months have passed from the creation of a new project in Unity to the publication of a beta version in Steam. 90% of the time was spent on creating, optimizing and licking the physical model, the rest 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, which were pulled by physical colliders. I decided not to suffer with a compromise and many special cases of destruction, but to create a simple system that works in all cases.
Did everything from interacting particles: earth, buildings, tanks of players, enemies, shells and bonuses - that's it. I implemented interactions between particles on a video card, because for parallel computing it is 50-100 times more productive than a processor.
The matter obtained from the particles at first looked strange, and resembled either liquid or gas:
And for the game you needed something strong, able to keep in shape. Having tried different ways of interacting particles, I found that the Lennard-Jones force gives the most durable substance. It turned out something like semolina porridge. For experiments, I added explosions at the click of the mouse.
Particles already have a temperature, and matter changes properties, melting from the heat of explosions. Matter itself holds volume, particles tend to form a hexagonal lattice. A small proportion of viscosity (in addition to the Lennard-Jones force) provides better stability of matter.
Here's the problem with stability. The discreteness of the model limits the magnitude of the interaction force between the particles, since at high speed the particles can become too close in one step, ignoring the steepest (twelfth degree) growth curve of the repulsive force. This will give them tremendous acceleration, which will make a new unnatural rapprochement even more likely. The law of conservation of energy is violated, matter explodes. And viscosity allows you to weaken this effect.
When the matter began to behave more or less satisfactorily, I collected a tank from the particles and made a control for it: at each step of the calculations, the data on the keys pressed by the player are transferred to the video memory, and these data are used to control the rotation of the wheels and the tilt of the gun:
Interacting with the physically realistic world was exciting, I was inspired. The game developed exactly in the direction in which I wanted.
Then I added a module for building the level from the picture: pixels were read, and physical particles were created in their place. In addition, matter “charred”, blackening from prolonged exposure to high temperature.
At this stage, the imperfection of the physical model was revealed. The stone columns behaved like jelly:
I had to sacrifice performance, reduce the sampling step, and thereby increase the force of interaction between particles, without the risk of instability. Matter became more durable, and I 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 to ash, and the ice is durable, but it melts easily.
Then I created several types of flying saucers from the same particles, and in the same place, in the shader code executed on the video card, I wrote a control system for the enemies. They aim well, dodge each other, and use different battle tactics.
It turned out already quite similar to a computer game in the traditional sense:
On this gif you can see that I used a new entity - a kind of bones that set the distance between the particles. They are also muscles, since they have a stiffness characteristic and a length that varies over time. So it became possible to strengthen tall buildings and make movable platforms at the levels.
In addition, I created a universal weapon description system that allowed me to describe a wide range of weapons of destruction, simply stringing some unified effects on others, creating chains of events. There were machine guns, flamethrowers, missiles frustrating in flight, the multi-beam suns of thermonuclear explosions, fans of lightning, love guns, and a whole bunch of power modifiers of matter.
And I also created bonuses so that I could pick up cartridges, strengthen the tank or influence the level according to the button-event principle. For example, here you can see what happens when a player selects a key:
You can also notice a semblance of an interface with health bars and other characteristics of a character tank, and with a list of available weapons.
The game can be published, I spent a week filling out a variety of forms on Steam, waiting for the results of the verification, designing the page and making the trailer and screenshots.
Greenlight was passed by that time, because as I was ready I published gifs on the reddit, causing steady interest in an unusual approach to building the world.
Finally, the game came out in early access, here is the trailer:
(Music - from the techno-opera of Victor Argonov “2032”. Not very suitable in meaning, but exciting).
Summarizing the development experience: the experiment showed that deep penetration of physics into the gameplay is technically feasible, but it is not yet clear how to use it to the greatest advantage for the gameplay. You still need to figure out what unique game features result from the physical world. I am currently working on a single player campaign in which I am trying to use unusual ways of interacting with the world, making a kind of hybrid of Lemming and a platforming shooter. In Lemming it was necessary to dig, blow and build a lot, and in a shooter - to shoot. Now, let's see which hybrid I can do. I hope the players will tell you. At the moment, in the published game, only the battle mode that imitates the game Scorched Earth is available.
The purpose of this publication is to share the results of this experiment with fellow developers. Perhaps someone will be interested in and want to devote more space to physics in their game. In comments certain to be asked about the incentive page, so immediately it will show .
10 months have passed from the creation of a new project in Unity to the publication of a beta version in Steam. 90% of the time was spent on creating, optimizing and licking the physical model, the rest 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, which were pulled by physical colliders. I decided not to suffer with a compromise and many special cases of destruction, but to create a simple system that works in all cases.
Did everything from interacting particles: earth, buildings, tanks of players, enemies, shells and bonuses - that's it. I implemented interactions between particles on a video card, because for parallel computing it is 50-100 times more productive than a processor.
The matter obtained from the particles at first looked strange, and resembled either liquid or gas:
And for the game you needed something strong, able to keep in shape. Having tried different ways of interacting particles, I found that the Lennard-Jones force gives the most durable substance. It turned out something like semolina porridge. For experiments, I added explosions at the click of the mouse.
Particles already have a temperature, and matter changes properties, melting from the heat of explosions. Matter itself holds volume, particles tend to form a hexagonal lattice. A small proportion of viscosity (in addition to the Lennard-Jones force) provides better stability of matter.
Here's the problem with stability. The discreteness of the model limits the magnitude of the interaction force between the particles, since at high speed the particles can become too close in one step, ignoring the steepest (twelfth degree) growth curve of the repulsive force. This will give them tremendous acceleration, which will make a new unnatural rapprochement even more likely. The law of conservation of energy is violated, matter explodes. And viscosity allows you to weaken this effect.
When the matter began to behave more or less satisfactorily, I collected a tank from the particles and made a control for it: at each step of the calculations, the data on the keys pressed by the player are transferred to the video memory, and these data are used to control the rotation of the wheels and the tilt of the gun:
Interacting with the physically realistic world was exciting, I was inspired. The game developed exactly in the direction in which I wanted.
Then I added a module for building the level from the picture: pixels were read, and physical particles were created in their place. In addition, matter “charred”, blackening from prolonged exposure to high temperature.
At this stage, the imperfection of the physical model was revealed. The stone columns behaved like jelly:
I had to sacrifice performance, reduce the sampling step, and thereby increase the force of interaction between particles, without the risk of instability. Matter became more durable, and I 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 to ash, and the ice is durable, but it melts easily.
Then I created several types of flying saucers from the same particles, and in the same place, in the shader code executed on the video card, I wrote a control system for the enemies. They aim well, dodge each other, and use different battle tactics.
It turned out already quite similar to a computer game in the traditional sense:
On this gif you can see that I used a new entity - a kind of bones that set the distance between the particles. They are also muscles, since they have a stiffness characteristic and a length that varies over time. So it became possible to strengthen tall buildings and make movable platforms at the levels.
In addition, I created a universal weapon description system that allowed me to describe a wide range of weapons of destruction, simply stringing some unified effects on others, creating chains of events. There were machine guns, flamethrowers, missiles frustrating in flight, the multi-beam suns of thermonuclear explosions, fans of lightning, love guns, and a whole bunch of power modifiers of matter.
And I also created bonuses so that I could pick up cartridges, strengthen the tank or influence the level according to the button-event principle. For example, here you can see what happens when a player selects a key:
You can also notice a semblance of an interface with health bars and other characteristics of a character tank, and with a list of available weapons.
The game can be published, I spent a week filling out a variety of forms on Steam, waiting for the results of the verification, designing the page and making the trailer and screenshots.
Greenlight was passed by that time, because as I was ready I published gifs on the reddit, causing steady interest in an unusual approach to building the world.
Finally, the game came out in early access, here is the trailer:
(Music - from the techno-opera of Victor Argonov “2032”. Not very suitable in meaning, but exciting).
Summarizing the development experience: the experiment showed that deep penetration of physics into the gameplay is technically feasible, but it is not yet clear how to use it to the greatest advantage for the gameplay. You still need to figure out what unique game features result from the physical world. I am currently working on a single player campaign in which I am trying to use unusual ways of interacting with the world, making a kind of hybrid of Lemming and a platforming shooter. In Lemming it was necessary to dig, blow and build a lot, and in a shooter - to shoot. Now, let's see which hybrid I can do. I hope the players will tell you. At the moment, in the published game, only the battle mode that imitates the game Scorched Earth is available.
The purpose of this publication is to share the results of this experiment with fellow developers. Perhaps someone will be interested in and want to devote more space to physics in their game. In comments certain to be asked about the incentive page, so immediately it will show .