How are video games programmed with the possibility of the playable character being able to go anywhere on the map without crashing the game?

520 views

How are video games programmed with the possibility of the playable character being able to go anywhere on the map without crashing the game?

In: Technology

3 Answers

Anonymous 0 Comments

Former game developer here,

There’s a big 3D coordinate system, and in it, you have planes, surfaces, and volumes. A plane is just some 2D flat, that expands unto infinity and can exist at any position and orientation. A surface is basically a 2D triangle in this space – unlike a plane, this surface has a boundary defined by it’s three points; we call them polygons. A volume is composed of polygons and is convex. There is also the concept of spheres, a volume which is a position and a radius, a ray, which has a starting point and a direction – conceptually it continues unto infinity, and lines, which has a start and stop point.

So now that we have some simple primitive constructs in a 3D space, we can perform some primitive physics on it: collision detection. The idea is to determine if any two things intersect. Your in-game character is represented by a simple cube. The game logic says, “here are a bunch of surfaces, let’s call it the floor. We know which side of these surfaces is top and bottom, and you can exist anywhere on top.” When you run into a wall, we determine if your box intersects that boundary or even surpasses it completely. We do some math and your character is positioned at the boundary. All this happens before we render a frame.

So there are boundaries all over the place, and anything that moves gets checked to make sure it remains in the bounds. You’ve certainly seen in games where you fall through the world. Of course that’s not supposed to happen, and there are shortcuts we take to reduce computation, and once you break that, sometimes you can sail clear into the void, as it were. Games have gotten better over the years.

You are viewing 1 out of 3 answers, click here to view all answers.