How Collisions Work in Games

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

I love these videos. Ive got a few questions about pruning though. In a game like star wars battlefront, youve got action happening all over the map. But i assume anything not on screen is being simulated somewhere else, correct?

👍︎︎ 3 👤︎︎ u/detourne 📅︎︎ Nov 08 2016 🗫︎ replies
Captions
have you ever wondered how hitboxes work and why people constantly complain about them have you ever stabbed the air next to a monster and somehow landed a critical hit today we're going to talk about how collisions work all right to detect any kind of collision whether it's a character's standing on the ground or running into a wall or getting hit by a bullet there are really two things we need to do first we need to define the boundaries of where a collision can occur on a character usually called the hit box and second we need to figure out if different boundaries are intersecting and what should happen when they do so first the hitboxes now if I fire a bullet at a character as long as that bullet hits the characters model they should take damage right well that seems pretty obvious and intuitive that would be a very computationally expensive way of doing things to check if a bullet is inside a character's model which is usually a pretty complex curved surface we might have to use a lot of calculus and processor-intensive subdivisions all occurring for each frame on every object in the scene so we need to make some approximations it would be more efficient to only remember a few values instead of a huge set of points and lines we could have a character's hitbox be a sphere for example we'd only have to remember the radius and center of the sphere and then check if something is inside of it but as you can see you could attack all of this empty space around the character and have it count as a hit which would be pretty confusing so let's say the next best compromise is to put a box instead of a sphere around the character for most objects and characters and modern games there's still enough extra whitespace that would make this pretty confusing and game-breaking but it works fine for something like Minecraft where the characters are already pretty blocky and combat precision isn't that important but for most games especially competitive ones we have to compromise computer performance for accuracy a little bit more so instead of having one big box we split the character until lots of parts and give them many different hierarchical boxes some people will study these really carefully in competitive games because the key is not to aim for the characters model that you see on screen but they're invisible hitbox which can sometimes be different by several pixels breaking a character's hitbox into this hierarchy also adds more depth to gameplay like how you can cut off tails in Dark Souls or Monster Hunter in these games for example you might have a separate hitbox for the tail associated with some invisible health meter and sometimes these enemies will have very specific and unintuitive hitboxes for the tails and you may end up killing them before you whittle away at their tail or whatever other appendage you were going for so we have our characters and monsters and bosses all split up into many different hit boxes and we have all these shapes that can collide with each other but how do we know if they're actually making contact well there are two mindsets for this we can try and calculate the exact instant two objects will collide ahead of time or for each frame we can check whether two objects have already intersected so let's say we have a character firing a bullet at a wall with the first method let's say we know the bullet is going to meters a second and the wall is two meters away so we tell the game to have the bullet bounce off the wall in exactly one second the second method however would check all pairs of objects each frame to see if they've already collided so it would check the bullet and the wall the bullet and the person the wall and the person and so on well the first method is way more efficient because it's one single calculation it's rarely used in games if the environment changes between the time the bullet is shot and the time it collides at the wall one single calculation cannot account for that the second method however is checking for collisions each frame so it can account for all of these changes but it's incredibly inefficient if a level has n objects that's n choose two combinations of pairs that have to be checked so for a hundred objects that's five thousand pairs that would have to be checked each frame there are a few ways we can improve performance here which mainly involves pruning trees basically to put it very simply if this whole box is our level we can subdivide it into smaller groupings of objects and only check objects that fall within the same grouping or subdivision so to get a little more technical we could say that this node represents the whole level and then we can split it into the left half and right half of the level and then continue to split it in half or based on certain object groupings now if we know an object is in the upper left of a level we don't have to look at any of these branches or these branches and we've cut down on a lot of computations this is what pruning trees means in computer science so there's a lot more that goes into pruning bounding box trees but that's a topic for another video for now I hope you guys understand a little bit more about collisions and why hit boxes can be so frustrating it's a trade-off between accuracy and computational performance so have a happy day wherever you are edie I'll see you guys next time bye
Info
Channel: TheHappieCat
Views: 177,439
Rating: undefined out of 5
Keywords: collisions, hitbox, hitboxes, collision, games, video games, gaming, game development, dev, gamedev, programming, algorithms, optimization
Id: z7xMIRzIDpU
Channel Id: undefined
Length: 5min 53sec (353 seconds)
Published: Mon Jan 04 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.