How physics are coded into video games

232 views

How physics are coded into video games

In: 5

5 Answers

Anonymous 0 Comments

Physics doesn’t really have a different coding method compared with pathfinding, shooting, enemy AI, etc. It’s just code that does math that happens to simulate physics.

Sure there are specific methods of doing so, but that can’t be answered without knowing what is the game is (programming language, libraries used, 2D or 3D, realistic or not, system specs, setting…).

Anonymous 0 Comments

Our understanding of physics can be proven or evaluated by math calculations. You then apply the same math to “physical” interactions in a video game.

Example, when a player jumps you determine the rate of how the player falls by using the same math calculations you would in the calculation of a person jumping and falling in real life. Then apply that to the player model and the camera and it will act/simulate the same physical movements as real life.

There’s tons of calculations included in these movement, you can apply gravity, resistance, force, etc. Calculations in this manner to replicate real world physics.

Anonymous 0 Comments

The physics of simulated objects can be calculated using a set of math equations. An object in freefall near Earth’s surface will always accelerate downward at 9.81 m/s^2. An object flying through the air will experience drag depending on the density of the air and the object’s shape and mass, and equations can calculate how much it slows down. When two objects collide, their mass, spin, velocity, and elasticity (bounciness) are put into an equation which calculates how each object’s movement and rotation changes.

So, calculating realistic physics in a video game is just a matter of constantly doing a ton of math to simulate how objects should behave based on how they’re moving and how massive they are. Depending on the game, these calculations may be done 100 times every second or more, with every object constantly having math done to update its position and movement.

Anonymous 0 Comments

A game has 3 main things it does endlessly while youbare playing:

1. Update all the things
2. Apply physics resulting from those changes
3. Draw the updates state of the game to the screen

These things happen in this order but at different intervals. These intervals vary depending on the details of the game, but they are happening many many times per second.

A simple example:

Player pushes ‘Right’ on their controller. In step 1 Mawio moves to the right.and bumps onto a Woomba.

In step 2, Mawios collision with the Woomba is processed and the Woomba sent flying accordingly.

Step 3 you see the flying Goomba on your screen.

Anonymous 0 Comments

Most areas of physics are described by differential equations, and there is a whole area of maths called numerical analysis which (in large part) focuses on techniques that can be used by computers to produce approximate solutions to differential equations. Most of these techniques were originally developed for use in research and engineering, but they can be easily adapted to computer games. The main differences are that (a) computer games generally need to simulate things in real time and (b) it’s not really that important if computer games are scientifically accurate. So basically you just cut a lot of corners and accept worse approximations. Nowadays, there are many off-the-shelf libraries that can do various physics calculations for games, so you generally don’t have to program any of it yourself.