Essential Maths For Beginner Gamedevs - Which Math is Useful?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this isn't a normal tutorial there are already plenty of those out there and this video will link to a few of them either in the info cards or in the description this video is therefore a meta tutorial video because well let me explain the internet is an almost limitless resource anything you want to know is pretty much available for free to learn and improve your skills and that previous statement is pretty much exactly true so why isn't everyone a super smart galaxy brain level genius in my mind there are two reasons for this the first reason is because we don't know what we don't know it sounds ridiculous but it's true how are you meant to learn something new if you don't even know it exists in the first place the second reason is school now school does a job of teaching and introducing us to a wide variety of new topics and ideas from my own personal experience school did a pretty good job of this however the thing i always found about school was that it didn't do a great job of linking its stuff to its actual practical applications in the real world it required a lot of blind faith and it wasn't until later in my life that a lot of these topics ended up coming up and being really useful it's a really weird feeling of oh i already know that because i did it two years ago in uni or i did it six years ago in school in this video i want to introduce you to some of the ideas and topics of maths that are used really frequently when making games with maybe a couple of examples when it's applicable i'm not going to show you how to do the actual maths of the topics i just want to show you the toolbox and help you draw some links between some things you might be doing in school and uni and their actual practical applications i'll be starting off with some of the more basic stuff and then moving on to some of the more complex stuff later on in the video but there isn't a strict order to the things i'm going to be talking about so be sure to subscribe and before we get going with the really useful ones i wanted to give a quick shout out to calculus it's incredibly useful when it comes to physics engineering chemistry sciences and even making game engines but when it comes to making the games themselves calculus tends to be not that useful it's one of those things which i've spent a lot of time learning in school and uni but when making games i basically never use it and it's definitely a lot less useful than a lot of the things i'm about to talk about now starting with we are going really basic with this first one numbers are fundamental to computers and so are essential when we're trying to make games you don't need to be brilliant at maths but having a basic understanding is kind of essential addition subtraction division multiplication all that stuff is useful all the time and something like controlling the order of operation with brackets is really really vital especially when it comes to logic which i'll talk a bit more about later on i think it's worth mentioning at this point though that you don't actually have to do any of this maths yourself the computer is doing all the calculations for you remember it's about knowing which tools to use and when so why do we need to use numbers well they're literally everywhere when we're making a game the amount of health you have the position of every object in the game the reload time the character's jump height and the character's walking speed even the respawn timer that you spend most of your time looking at because you're bad at games all of these things that go into the way a game operates need to be stored as numbers somewhere i don't know if there's any tutorials just generically for numbers because i've never really looked them up so if you want to practice all i can really suggest is dr kawashima's brain training for the nintendo ds i promise i have good links for the rest of the topics so with numbers out of the way i can introduce the most important umbrella term that links computers maths and by extension game dev discreet maths it's a topic that's been around for a very very long time but experienced a very big boom in research and interest when computers started becoming more and more relevant in the last century a lot of universities around the 1980s then began to develop a discrete math support course for their computer science students and even now if you end up going to university to do computer science like i did you will likely end up doing a discrete math course or something similar to it and it's really useful because well computers are discrete mathematical machines i've taken a lot of maths courses over the years and without a doubt discrete maths is the most useful and applicable one that i've ever taken because of this most of the topics i'll talk about from now on not all of them but most will fall under this discrete maths umbrella if you decide you want to go and look this stuff up yourself one of the core foundations for making games and programming is logic binary logic specifically sort of provides the foundation for computers and programming if you've ever used an if statement you're using binary logic i would say that this is one of those core absolutely necessary things that you should probably get a handle on if you've never done any programming before learning how and and or operators work will probably be the most frequently used and useful things using brackets so that you can organize more complex binary logic will also come in really handy so like i said this is used literally everywhere a really basic example could be something like this if the space bar is pressed make the player jump the part in the if statement is binary logic it's checking if it's true or false this can then extend even further perhaps you only want your player to be able to jump if they're touching the ground so you'd get something like this if the space bar is pressed and the player is currently touching the ground then make them jump all games are just a constant blitz of if this thing happens in the game then make this other thing happen in response and yeah binary logic can also find its way into other parts of making games beyond this simple if then type of logic one of these examples could be bit masking this is a really elegant use of binary logic and is really often used to automatically place the tiles in a tile set so that they will connect up properly i even use bitmasking in my project that's in the background called project drifter to make sure that the room layouts all connect up properly as well and it really does just pop up in lots of locations there are these things called two sat computational problems that appear in a huge amount of different circumstances that you wouldn't even consider at first glance and this is basically a constant theme with all of the things i'm going to talk about today and just maths in general there's basically always more you can learn and apply in different ways and i think these topics serve as really good starting points for that sort of eternal student mindset the next thing we're going to talk about is coordinate systems so the way we talk about coordinate systems and maths is generally a bit more complicated than we need to to make games but the ideas and foundations it provides us with are incredibly useful coordinate systems are essentially there to let us know where certain things are relative to other things within the same coordinate system so why do we need to know this well pretty much every single game engine or graphics library will use the xy coordinates for a 2d game and an additional z coordinate for a 3d game for anyone interested this follows a cartesian coordinate system and if this sounds simple to you well that's because it is the x and y axes are introduced to us very early at school at least where i'm from and the concept of it is generally quite intuitive to us so basically everything we use on computers that display in a graphical manner will have to use coordinates if it's a 3d game a 2d game a ui based game the computer will need to know where things are in order to draw them onto the screen coordinates are just needed some game engines particularly 2d ones might also have an inverted y-axis which is just something to bear in mind just as a footnote to this section there are other coordinate systems i used polar coordinates to make this game jam game a while ago now these are really interesting in a different way of making a game but you do end up mapping things back onto the same xy computer coordinates because that's what it understands it can be really interesting to explore these other ideas though so i just thought i'd mention it here next topic trigonometry triangles and circles are all linked together on a fundamental level it's mostly to do with angles and as it turns out angles are quite useful and this is where the trigonometric functions of sine and cos come in really handy sine and cos are functions that you give an angle and then they spit back out a value between one and minus one depending on the angle you gave it now these wavy boys in particular find their way into so many different areas of maths so here's the main use case for signing cos when making games say you know the angle you want something to move at on your screen and you also know how far you want it to move in that given angle sign and cos help us convert that angle and that distance into x and y coordinates that we can actually use to move our objects this works because we're constantly making imaginary right angle triangles on our y and x axis because they're perpendicular to each other so like i said moving things at a given angle and a given distance using sine and cos is really common but i do often find myself using these functions in a completely different way when i want to make something happen repetitively like i said earlier these functions are really wavy boys they are a pattern that just repeats forever this is such a useful shortcut for quickly animating stretching effects like this i have a base scale for all these little nuts and bolts and then i use the sine function on top of that base scale to create a value that keeps going up and down to make the stretching effect of it going out and in i've also used it for a small bobbin effect on enemies that float through the air before these are just some niche hacky ways i like to use them but these functions will always be useful when you're trying to work out positions and angles for things but they can also just pop up in random algorithms that you're researching for example this infinite terrain generation uses a variety of different sine waves to create all the different hills and valleys and all the different details on it as well trigonometry is pretty essential to vectors which i'll talk about later on but after talking about sign and clause for a while and all this stuff relating to triangles i do have to mention pythagoras theorem this is immensely useful because it lets us find the distance between two points this is really useful for things like circle collisions but can also just be used for knowing how far away two things are from one another a really common example of this is waypoints in games like skyrim they tell you just how far away your character is from the waypoint you see in school we learn about all this stuff in the context of triangles because that is where all of these things are mathematically derived from but in reality we just skip over all the fluff of drawing imaginary right angle triangles and stuff and just use the useful bit pythagoras's theorem is also very crucial to the way that vectors work which is what we're going to talk about next so that classic thing that anyone ever says when they first try and teach someone else about vectors is that they have magnitude and direction what does this actually mean though well i find it easier to explain with a quick example a 2d vector is made up of two components and that is generally an x and a y component especially in games the x component tells you how far to move along the x axis and the y component you guessed it tells you how far to move along the y-axis when you're making games that's generally about all there is to a basic vector your player's position could be stored as a vector for example it could have an x-component of 50 and a y-component of a hundred but you could also store your player's velocity as a vector as well so the velocity vector could have a component of two in the x-axis and minus four in the y-axis this would mean that every time you wanted to update the player's position in the game you would add the velocity vector to the player's position to get a new position vector but that's not the only use that vectors can have they're used literally everywhere in games when you see something moving in a game world it's probably been done using vectors the lighting in games will also use vectors and a lot of collision engines will make use of vectors as well so yeah in my opinion they really are one of the most important things to get a handle on there are some special things you have to note down with vectors though they have their own slightly different rules when they're compared to regular maths these rules are generally quite intuitive but do require their own way of thinking most game engines will have some sort of functionality that will handle a lot of the vector operations for you so again this saves a lot of time because you're not actually having to do any of the maths yourself just be sure to check the documentation the first few times you use them to make sure it's actually doing what you think it's doing you can also do this thing called normalizing a vector this takes a vector and then changes its size so that it's only one big but it keeps on pointing in the same direction and why would you want to do this well a really common example of using this is to fix wasd or arrow keys movement in a game it's a very common beginner thing to start with a movement system that sounds something like this say that when we press up or down in our movement system we move the player one space up or down when we press left or right in the movement system we're going to move our player one space left or right and this seems good when we move we always move the same distance in every direction however if we press up and right at the same time we end up moving one space up and one space right at the same time using pythagoras theorem we can actually calculate that we've moved root two or roughly 1.414 spaces in the diagonal this means that you end up moving faster in the diagonal directions than you do in the sideways and the up and down directions to fix this normalization is used normalizing the vector ensures that we're still moving in the same direction diagonally but it restricts the distance we travel to be the same as every single other direction so now we move at the same speed whether we're moving sideways up down or diagonally funnily enough i don't think undertale normalizes its diagonal movement so you end up moving faster when you move diagonally in undertale than you do when you're moving sideways or up and down it never really matters or impacts the gameplay in any meaningful way i just think it's quite unusual and interesting to see there's also this thing called the dot product the dot product is a special thing you can do with vectors it lets us know how similar two vectors are to one another it tells us how much they are pointing in the same direction so if i have two vectors that are pointing in the exact same direction the dot product is one if i have two vectors that are pointing in opposite directions the dot product is minus one because in opposite directions they are as different as they can possibly be and all the parts in between them pointing in the same direction and pointing in the opposite directions are between one and minus one and if the one and minus one thing seems familiar that's because this is another place that trigonometry pops up quite a bit i found this video that's really good at explaining this concept and showing you how to do it but why is this useful well it comes in surprisingly handy quite often once you know it exists i saw a really good example of it recently in codia's latest video where he compares the up direction of the camera with the forward direction of the player this helps the player climb smoothly over all of the different surfaces regardless of which direction they're climbing in it's really cool you should check out the devlog i've also used it in my game to compare the car's velocity vector with the direction vector for shooting the weapon this helps me adjust the bullet speed to the car's momentum so that i don't get any weird backwards moving bullets or bullets that the car can then overtake another unique thing that can be done with vectors is something called the cross product this usually assumes we're using 3d vectors and helps us analyze the differences between two vectors the result of a cross product is perpendicular to the two vectors that went into it so if you imagine we took the cross product of a vector that went along the x axis and the second vector went up the y axis the resulting cross product would be along the z axis this is used again loads in lighting as it's very useful for working out which direction a polygon or a surface is facing a more game dev example could be for enemy movement you could take the first vector as the direction for the enemy to look at the player the second vector could just be pointing straight upwards out of the enemy's head cross product of those two vectors would be perpendicular and allow the enemy to move sideways relative to the way it's facing which would also involve moving around the player quaternions is something i always see mentioned when people ask what sort of maths do i need to learn in order to do game dev quaternions are incredibly and completely undeniably useful when rotating objects in 3d space i think of them as sort of a rotation delta they are the shortest path to get from one orientation to another you can have a quaternion that represents the current orientation of an object or you could use a quaternion on another quaternion to rotate the first one by the second kind of like how with vectors you can have a vector for a position but you can also have another vector to move that position but and it's a big bud normally you won't need to know how they work an engine like unity just handles so much of the complexity for you i really do sometimes question how useful it actually is to know the quaternion process by hand you see so much of computer science is building on layers of technology that are underneath you that have already done some of the leg work i do really struggle to weigh up the sort of time investment versus the reward for something like quaternions you can easily spot when you need to use quaternions it's just when something needs orienting or rotating in 3d space but then you just use a library like unity's quaternion class to do all of the grunt work so even just by using unity you're already using quaternions because it stores its rotation as quaternions but there is nothing wrong with learning exactly how it all works if you want to it does sort of improve your foundations for it but i've never personally found it that useful graph theory is another topic that pops up quite often when we're making games and these graphs are quite different from what you might be imagining in a bar chart or a pie chart these graphs are mathematical structures to model the relationships between objects they basically let us link and relate things to one another we use them for things like pathing algorithms to help ais find their way around the level without crashing into walls pathing algorithms can also be used to check that a randomly generated level is traversable that is you can go from one end to the other without having a wall that spawned in the way to stop you from beating the level we also use grafts for finite state machines finite state machines are used a lot in unity for animating things switching between states depending on what the player is doing or what the enemy is doing finite state machines can also be used to model the behavior of things perhaps they can be used in a stealth game where a guard moves between states of high alert and searching or resting or being confused a thing to note with graphs is that you don't always have to directly and explicitly implement them into your games sometimes you will end up doing this but they can quite often serve as just a really good planning tool for working out how you think something should work kind of like a workflow so that was a long video like i said earlier hopefully this is a reasonable resource to start pointing you in the key areas of maths that are used really frequently in game development there are of course lots of different other areas of maths that can be used in lots of different circumstances so feel free to leave a comment if you think of any other useful things that you feel like i missed that other people should know about subscribe and like if you liked the video follow me on twitter join the discord where i'm usually happy to help if i'm free and until next time [Music] goodbye [Music] you
Info
Channel: Madbook
Views: 98,274
Rating: undefined out of 5
Keywords: math, maths, important math for making games, math needed to make games, most useful math, vector math, what maths is useful for games, what math is useful, indie game math, game dev math tutorial, maths useful for games, how to do math, math for games, math games, gamedev maths, gamedev math, math to learn for games, math tutorial gamedev, maths tutorial for gamedev, indie game maths, learn indiedev maths, pythagoras theorem, quaternions unity, unity maths, unity math
Id: iPWWrM81z-o
Channel Id: undefined
Length: 20min 25sec (1225 seconds)
Published: Mon Jun 14 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.