Black Myth wins the award! How is the most realistic physics engine in the game achieved? It's incredible...

Black Myth wins the award! How is the most realistic physics engine in the game achieved? It's incredible...

This year, our domestic game "Black Myth: Wukong" won many international game awards. Recently, the game has been updated, and many people are excited to download Black Myth again to experience the 81 difficulties again.

However, some people can't help but be curious about how the physical processes in the game are so realistic, such as ripples in the water and traces of movement in the snow. Why do these interesting phenomena appear? What inspiration do these phenomena have for physics itself? Let's walk into the physical world of the game together.

Collision detection, virtual "hard objects"

In the classical physical world, the most common event is collision . Therefore, if you want the game to be realistic enough, collision must be the first process that needs to be considered.

Let’s first look at how the collision of the classical world occurs.

F is the net force on the object, m is the mass of the object, and a is the acceleration. By calculating the net force and torque on the object at each moment, we can get the physical state of the object in real life. Similarly, back to our game world, the physics engine can use this method to update its velocity and position.

Simulating Collisions in Unity 3D

In computers, this is usually achieved through numerical integration methods, such as the Euler method, the Runge-Kutta method, or more stable and advanced semi-implicit integrators . In games, computational efficiency and stability are usually prioritized to ensure that the approximate and accurate position and state of objects can be quickly obtained in each frame refresh.

However, as we all know, the real world is classically continuous, but the simulation of the game world requires updating the position of each object frame by frame according to the state of each object. The higher the frame rate used for physical simulation, the more accurate the calculation result will be.

For example, we calculate the collision of two balls. When a collision occurs, we calculate the result of the collision based on the speed, direction, material, and collision depth of the two balls, and update the status of the two balls at the same time. However, in the real world, two rigid objects will not "overlap". The real collision occurs at the moment when the two balls touch or during the entire process from contact to deformation to the end of the collision.

Example of overlapping collision in the game

However, since the physics engine updates the position and calculates the collision results frame by frame, it cannot guarantee that the time of the collision will be exactly on a certain frame, nor can it truly and completely simulate every subtle change in the process of the two balls from contact to separation. The collision information between the two frames is actually lost, which will lead to many more complex collisions that sometimes seem very counter-intuitive.

Many mature game engines now avoid this problem by separating the game's calculated frame rate from the actual frame rate. However, the frame rate is not the only factor that affects collision.

The actual modeling in the game process is very complex for the sake of aesthetics. Generally speaking, the model has thousands of triangles. However, the calculation amount of the physics engine will increase geometrically when calculating the collision of these original models, or due to some strange modeling angles, the collision calculation will give a result that is very different from reality. Therefore, we need to simplify the physical appearance of the object, which is what we often call the collision volume in the game.

In addition, materials, friction, air resistance, extrusion, etc. are all issues that need to be considered in a collision.

Constraint: restricted freedom

In addition to the collision of rigid bodies, the game naturally requires the connection and rotation of many parts, which is the physical concept of constraint. For example, if the little man in the game wants to grab an object, it is equivalent to the contact surface between the hand and the object generating a constraint.

In physics engines, constraints are used to limit the range of motion and relative positions of objects. They are widely used in games and simulations, such as character skeletal animation, robotic arms, wheels , etc. In the simulation process, if the constraints are not done well, it is likely to get very strange game screens.

In classical mechanics, constraints are conditions that describe the relationship between objects or objects in a system. Constraint mechanics is the branch of study that studies how to consider the restrictions on motion in a multi-object system. The relative motion between objects is subject to different types of restrictions, depending on the degree of freedom.

In physics engines, constraints are usually described by mathematical equations and solved based on Lagrangian mechanics and Newtonian mechanics in classical mechanics.

The relative motion between objects is determined by the constraints imposed on them, which make the objects follow the agreed trajectory and prevent them from moving in a way that does not conform to the laws of physics. Specifically, the constraints limit the degrees of freedom of the objects by changing their acceleration, thus ensuring that their motion does not violate the constraints.

The character's joints are a form of constraint, called hinge joints, which allow two bodies to rotate around one axis while restricting other degrees of freedom. The physics behind this can be traced back to the Moment of Inertia and the Conservation of Angular Momentum.

In actual games, constraints also have the problem of computational limitations, and the amount of computation needs to be simplified, so there are usually pre-set general constraints in the game, such as the following

PhysX Joints Example

Cloth and fluid simulation:

Deformation and flow of objects

In games, simulations of soft bodies, cloth, and fluids are used to present the deformation and flow behaviors of objects. These behaviors not only follow the laws of classical physics, but also rely on numerical calculation methods to achieve them. Through these simulations, games can show more delicate and realistic physical effects, such as ripples caused by characters running in the water, and nearby grass and trees blowing when weapons are swung.

Soft bodies are objects that deform under external forces. Compared with rigid bodies, they are no longer completely indeformable. The core goal of soft body simulation is to accurately describe the deformation behavior of objects when subjected to forces.

The deformation of a flexible body is closely related to stress and strain in physics. Stress describes the distribution of internal forces of an object under the action of external forces, usually expressed by a stress tensor. Strain describes the change in shape or volume of an object due to external forces.

Relationship between stress and strain: elastic bodies will experience linear or nonlinear strain under stress. The most commonly used model is Hooke's Law, which describes the linear elastic behavior of materials under small deformations:

Schematic diagram of mass model

The mass model is one of the most commonly used methods for calculating simple soft bodies. In this model, the object is discretized into a number of mass points, each of which is connected to each other by springs to simulate the elastic behavior of the material. The equation of motion of each mass point is given by Newton's second law.

Bullet engine shows cloth effects

For more complex object deformations, we can use the finite element method . It simulates the overall behavior of the object by dividing the object into many small units (such as triangles or tetrahedrons) and solving the stress and strain of each unit. This method is often used to simulate more sophisticated object deformations and can handle nonlinearities and large deformations.

Fluid simulation is one of the most challenging tasks in a physics engine, especially in terms of realism. Fluid behavior is profoundly affected by continuum mechanics, especially fluid dynamics and thermodynamics.

The motion of the fluid follows the Navier-Stokes Equations, which are the basic equations describing the flow of viscous fluids:

The left side of the equation is the inertia term, which describes the change in momentum of the fluid; the first term on the right side is the pressure term, which describes the force generated by the pressure gradient, and the fluid flows from the high-pressure area to the low-pressure area; the second term is the viscosity term, which describes the friction (viscosity) effect inside the fluid, which is related to the gradient of the velocity field of the fluid; the third term is the volume viscosity term, which is to consider the volume viscosity of the fluid; the last term is the external force.
For incompressible fluids:

Then we can ignore the volume viscosity term. In the game, we can even ignore the viscosity term and only consider the two-dimensional case, and we get a very simplified set of equations, which greatly reduces the amount of calculation:

However, the resulting fluid simulation is relatively simple. For example, it is difficult for us to see ripples on the water surface in a long range in the game, which is equivalent to ignoring the long-wavelength part of the fluid fluctuations.

The ripples on the water during the fight in Black Myth

The difference between simulation in games and in scientific research

Whether in game development or scientific research, it is necessary to simulate the movement and interaction of objects. However, rigid body simulation in games and rigid body simulation in scientific research are significantly different in terms of goals, accuracy, calculation methods, constraints, and solution strategies.

The simulation in the game focuses mainly on real-time interactivity and visual realism. Although the objects in the game move according to the principles of Newtonian mechanics, the accuracy and details of the simulation are often simplified in order to achieve a better user experience and faster calculation speed. The simulation results are more used to enhance the player's immersion rather than accurate physical prediction.

The goal of rigid body simulation in scientific research is usually accurate modeling and performance evaluation , which is used to analyze the mechanical behavior of objects, design optimization or experimental verification. The purpose of simulation is to provide reliable results for practical applications, theoretical research or verification of physical phenomena.
Although simulations in games and in scientific research are based on the same physical principles, simulations in games are usually greatly simplified to ensure that the movement of objects can be calculated efficiently in each frame.

I wonder if you have a deeper understanding of the physics in the game. Here is a game screen from Black Myth. You can imagine how many physical simulation processes are contained in it.

References

[1] Eberly, D. (2003). "Game Physics." Morgan Kaufmann.[2] Witkin, A. & Baraff, D. (2001). "Physically Based Modeling: Principles and Practice." SIGGRAPH Course Notes.[3] https://www.zhihu.com/question/277300055[4] https://developer.aliyun.com/article/432351

[5] https://zhuanlan.zhihu.com/p/679061686

Planning and production

Source: Institute of Physics, Chinese Academy of Sciences (ID: cas-iop)

Editor: Zhong Yanping

Proofread by Xu Lailinlin

<<:  One lie down, two clap, three roll, fall into the ice hole, remember this can save your life →

>>:  What kind of “beast” is the green-faced beast, and what kind of “ghost” is the red-haired ghost?

Recommend

What are competing products? 8 ways to collect competitive products

First of all, what is a competitor? Why do we nee...

Advertising high-quality landing page design template

Some time ago, Desert Platinum Camel Milk was doi...

Unprecedented! Another major discovery in Sanxingdui

June 13 Sanxingdui is "updated" again A...

Experts suggest: Eat only 70% full for dinner! How full is "70% full"?

Expert of this article: Pa Lize, Chief Physician ...

"Wen Jun Screenwriting Master Class" Enters the Film Industry from Creation

The film screenwriting master video course teaches...

What does it mean when beauty relies on beauty?

Beauty leans on beauty, what exactly is beauty le...

These 20 "health care" suggestions are all wrong, don't be misled anymore!

“Drinking more porridge can nourish the stomach”,...

The closest I've ever been to the moon is through a telescope.

In spring, everything comes back to life and the ...

With just 15 seconds of audio, AI can help aphasics “regain their voice”?

OpenAI shared some of their progress in AI speech...