What causes clipping and why is it such a common bug in video games?



I’m playing *Cyberpunk 2077* right now, and it’s a beautifully rendered visual masterpiece of a game, but the clipping issues are ubiquitous to an almost absurd degree.

You see this in “finished” games as well (particularly the Soulsborne series where I can’t count how many deathblows have come by way of an enemy’s attack landing right through a wall or floor).

I’m curious as to why it’s so common. Thanks in advance!

In: Technology

No expert but, objects come togeather in the game, u see perhaps a wall and the character, the game will see it different, using hitboxes which are simpler geometry to keep things efficient. So the boxes collide but the animating of the character won’t be perfectly in sync so they can pass through on occasion. Add in enemy characters and u can get hits through objects or whatever.

First because it would be hard for a computer to keep track of where ever part of your character and the surroundings are. So to make the game runnable, developers use simple shapes and put fancier more detailed pictures on top of them. The boundaries of the picture aren’t tracked and can overlap.

Second because computers and video game worlds aren’t continuous, they’re a series of frames (fps). All those tracked parts of your character are really teleporting a small distance every frame. For the computer to prevent clipping, it has to determine if a part of you character has teleported past a part of another object. That collision detection method can also be hard to do, and the easier methods of doing it can sometimes be fooled if a part of your character teleported far enough away from the ‘wall’. That’s why a lot of clipping will happen when your character is moving quickly: they’re teleporting a larger distance every frame which increases the chance you’ll fool the collision detection.

It’s nearly impossible to perform accurate collision detection. Not theoretically impossible, mind you, but very computationally expensive. To see why it is, just imagine if you have 2 moving triangle, you know the position and momentum of each, and you need to determine if and when they touch each other in the next second. No you don’t get to see the triangles, you just have the numbers to calculate. You will quickly find out that the math is a mess.

Now imagine a computer has to do a lot of these checks. All that, just to even merely *detect* a collision.

Next, even if the computer does detect collision, what is it going to do with it? To do anything accurate/realistic-looking, you need to model force, density, tension, etc. which are also very computational expensive. Sometimes they try, and you end up with wonky ragdoll physics, which lead to corpse flying or vibrating on the ground. Which is why computer often have very minimal response to collision detection. Oh, you collide a wall? Your main velocity is now 0. That’s about it. Many other stuff don’t change at all. A fighting animation won’t be altered, because a fixed animation can be hard-coded and blindly executed by a computer without much work, but a changing animation based on physics is very computationally expensive.

Combining the above problem, the game developers solution is to use collision detection using very few, very basic shape (the hitboxes), and they follow predetermined path according to a fixed animation. The result of this is that the hitboxes can always clip through wall.

Can you just check LoS? Not really, that’s still janky. The math for checking LoS itself is also very complicated in general, so game developers also have to shortcut this by checking from a few points only. Check LoS from a single point and you run into a problem where what looks like clean hit get blocked by random dust or some tiny object that shouldn’t matter. Check LoS between many points and the computational problem come back. That’s not to mention, many maps have invisible collision box due to the mistakes (hard to avoid when making map is so complicated).

The cheapest, and less expensive option is simply trying to make hitboxes close to accurate, and make the wall/floor *thick* so that the hitboxes don’t clip too far that it come through the other side. But this is also quite complicated. Adding a new animations? Opps we already made the map. What if the wall you need is too thick that things just looks wrong and out of proportion.

Everything visible in a computer game is made up of a mesh of small triangles. Triangles are made up of three corners known as nodes. The face of the triangle has an “inside” and an “outside” face. On a properly meshed item in the game, all the outside faces should face outwards on the object.

If you take a single point and want to work out if it’s inside or outside a 3D object, you need to work out whether that point is on the inside or outside side of every single triangle making up the 3D object. To be inside the object the inside face of every face must face the point.

Now to truly check if two 3D objects (A and B) are overlapping – you check every single node on one object A against every triangle on object B and then do that again but compare every node on B against triange on A. In a game where everything is comprised of millions of triangles with hundreds of objects, very quickly this is computationally infeasible. (Not to mention self-collision, working out if a flexible thing like a player character is intersecting with itself is an even bigger headache!).

So the games cheat.

Lots of objects in the game have another simpler set of geometry that’s not rendered, but used for collision. This geometry, primarily made of cylinders, spheres and cubes allows you to use a load of mathematical tricks such that you can check if any of these shapes are overlapping way easier. For example, two spheres, you just measure the distance between their centres and work out if it’s less than the sum of the two radii. The problem is, these shapes don’t match the 3D mesh perfectly so some clipping is inevitable.

With thin things like walls, it’s easy to make some optimizations that means collisions aren’t always detected. For example, you might simply not allow the enemy characters’ centre within a certain distance of the walls. That way the enemy character should never be able to move through the wall, and you don’t even have to bother to do a collision check – excellent! Except this shortcut doesn’t stop part of the enemy moving through the wall – like a sword!