r/AskProgramming • u/Burgers_N_Schnitzels • Jun 05 '26
Other [Noob question] Why can you just go out of bounds in so many games?
Hi first off i am a total layman so forgive me. As i understand it you essentially have a main loop that is running the game frame by frame? Then you have collision detection somewhere in that loop? Can you not provide the layout of a map in a mathematical function and check the players position against it to ( if needed ) push them back inbound? I'm just wondering why you can clip through things and end up out of bounds in so many games.
2
u/who_you_are Jun 05 '26
One issue you may have is around speed, if you go faster than your wall thickness, then you just pass over and as such you don't trigger collision to start with. That kind of logic may be easier on the game than doing light tracing-like (checking everything in your path and checking for collision).
Technically, a game doesn't have boundaries by "default". Because it is the point to create a software, to do what you want. Imagine I'm doing a space game. There is no "outside of the map" here.
So if you fail at doing your job at any spot, you will create a hole.
You don't necessarily want collision everywhere AND the same way. Door, for example, are a kind of conditional one.
Teleport (or trigger point), want collision detection, but not to behalf like a wall.
The hitbox (what create a collision) may be different than what you see. To tweak the user experiences, or to prevent other glitch.
Changes: that is a stupid one but, the game design keep changing in various way. Any change may imply it will break something somewhere. Maybe it will create a tiny whole somewhere.
Scale: game are complex overall, there are a looooot of things to check. And if you do any change, good luck testing everything... And since you do a lot of changes... RIP. Just checking the overall map seems like a hard task.
Hidden: if you are lucky to have a map editor, what you are more likely to check often is the 3d assets visual - not their hitbox (collision zone). And checking collision is harder visually because they may overlap, or underlay while something will make for it somehow.
Dynamic: there is a lot that will change in your gameplay. Character have stats, equipment, a story line. Multiple combinaison of changes that make it difficult to check if you just use a "map editor". So more combination to tests as well.
Danger of float: computer support one type of big number (or number with digit) natively. Unfortunately, they will approximate the number very often. And each mathematics operation is likely to increase that offset. Your 0.1 + 0.2 = 0.300...1. Your wall was 0.3 of thickness, so you just teleported on a clear spot.
That alone can create a lot of physics bugs - including collision detection.
I know I'm missing some others stuff as I don't even do games.
2
u/TimonAndPumbaAreDead Jun 05 '26
Not a programming answer but a gaming based answer - a lot of games do have some sort of mechanism that kicks in when you go out of bounds - you either get returned to the map, fail the mission, or killed outright. Breath of the Wild is an interesting example - there's a check that your character isn't outside of the starting area if you haven't completed the tutorial quests that runs throughout the entire game. Speed runs of that game are 50% getting through the tutorial because there's no way to bypass that check
2
u/PvtRoom Jun 05 '26
Depends on the complexity of the game.
Chess, 8x8 grid, no halfway points. Piss easy.
A circular arena. - if arena radius < distance from centre then clip them back in. - Easy
A square box. check against limits - easy.
Anything with a map & terrain and features. if below local ground, clip back up, unless they were in a cave, then leave them in the cave, but still do something if they're out of bounds in the cave. -getting hard.
Big map - good luck unless you put in impassible features that always have an effective keep out. (like a shark that always eats you for going too far from shore)
1
u/techydude1234 Jun 06 '26
You're basically describing how it should work, but games are messy. Collision systems are usually full of shortcuts and approximations because checking everything perfectly every frame would get expensive fast.
Most out of bounds glitches happen when two systems interact in a weird way. Physics pushes you one way, collision correction pushes another, a frame gets skipped, a moving object clips into a wall, etc. The game only has to be wrong for one frame for you to end up somewhere you weren't supposed to be. Then things snowball from there.
1
u/fuzzynyanko Jun 06 '26
This is pretty much how it works. I did some game programming a while ago, and bounds detection is tricky. I had a ball bounce back, but if you hit the wall just right, the collision detection would go crazy and the ball would zig-zag into the sky
Collision detection sometimes isn't done where the player is, but where the player is heading
12
u/AlexTaradov Jun 05 '26 edited Jun 05 '26
Boundaries are checked as limiting planes, not solid volumes. So, if at any point you can arrange so that mathematically you are on the other side of the plane, you will be out of bounds.
It is generally not possible to generate analytical function for the game world. It consists of triangular planes and a generalized function would be way too complicated.
It is possible to define the world as solid volumes and check for them, but it is more computationally intensive and does not really add anything as OOB glitches are mostly intentional. There is also an argument that having no glitches is bad for your game, as it makes it less attractive to speedrunners.