Math for Game Devs [2022, part 1] • Numbers, Vectors & Dot Product

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
apparently there was a button on YouTube that I had to click to go live I thought it would just go live as soon as I started streaming but apparently not should be live now right um okay now it's working okay neat sorry about that I usually stream on Twitch I'm not very used to YouTube and so so things might be a little janky um meat I need to pull up a document why not on Twitch I want to try doing this on YouTube because I feel like the audience on YouTube is more like diverse while twitch is very gamer Centric and so I want to see see if I can reach my target audience better on YouTube so that's why I'm trying this now oh yeah and then also on Twitch my students get ads which is kind of kind of frustrating and yes there will be a recording it'll stay on YouTube as soon as it's done where are my notes here we go okay what do you do you have a class emotes like like an emote you use a lot like the previous students were using this like business emote like this one anyway react react if you are present just to see if all of you are here just react react with your favorite emote so that I can see that you're here maybe I shouldn't have said favorite emo maybe I'm gonna get like 50 different things now neat okay people are present that's good I'm not entirely sure if I'm present um I am somewhat tired and a little bit sleep deprived so I hope that's not gonna affect things too much um okay all right I guess we're ready to start um so maybe I should say who I am and my name is Freya Homer I am a game developer and I have been for 12 years I think I've been doing this professionally um and then I've sort of been pivoting into doing more educational content while obviously teaching um and doing kind of like Tech Arts stuff publicly so I'm generally pretty focused on math shaders and that kind of stuff um so yeah I have been working at various smaller companies I'm doing freelance work I co-founded a studio called neat Corp where we worked on a game called budget cuts that was kind of like a VR VR game uh and I've since left to work on my own projects and my own projects are usually uh tools for Unity so I've been I made a Shader editor a long time ago called shaderforge so this was before Unity had their own node-based Shader editor um and then more recently I have um I created a plugin called shapes which is a vector graphics plugin for Unity so that's kind of my the projects that I've been involved in that are most known I suppose um yeah and and so that's that's who I am um okay and then let's let's jump into it um so I just want to talk a little bit about like what my purpose is like why why am I here to to teach right um and I'm here to make you learn I want you to get the tools that you need to code games so everything I do is going to be centered around game development you know when you're in math class in school quite often it feels a little bit like irrelevant like when am I ever gonna need the derivative of how many packets of pasta I buy like during a year like I feel like there's a lot of math that feels pointless and esoteric and so um so I think centering something around game development is a really nice way to contextualize as for why these things are useful because quite often it feels pointless and and so at any moment feel free to ask me when when are we ever going to use this like what's a use case for the dot product or whatever so just feel free to ask anything at any time um because I do want to focus on things that are useful um and so sort of by extension I I don't really care about whether or not you finish the assignments I give you I don't really care about grades I I don't care about that at all um so it's all about like what you learn and what you are able to do and how much I'm able to help you that's my goal um For Better or For Worse I think you might get assignments from your head teacher at some point because like I'm guessing you're required to um but but yeah so so that's sort of how I look at it I suppose I hope that makes sense um so with that being said keep in mind like what standard you're setting like not only for yourself but like for others as well in class like if you don't do any assignments at all and you just kind of don't really watch any of the lectures you don't learn anything you're kind of you might come off as a little bit lazy to your your like fellow classmates and keep in mind that your fellow classmates are going to be in the industry pretty soon and if if they have a view that oh you're the person that doesn't do anything they're not motivated they don't get anything done then then keep that in mind that um like for instance like there was one time I had a class and I noticed that that a student basically never showed up on time they never did anything um properly and they cheated um and so like my impression of them is not very good and so so I just want you to keep that in mind that like all of you will be in the industry it's not like you are separate from the industry at this point um so so be so so keep that in mind be be proactive and and whatnot um okay uh will the assignments be made and graded by you I will make the assignments but I will not grade them um the assignments will depend on where we are in class because the time scheduling is going to be different um so it depends on what we've gone through and uh what you know at that point uh if you've been following class um yeah so so they they will be similar to the 2020 assignments but I'm not entirely sure if they're going to be the same it depends on where we end up at the end of this um lecture um yeah so you can use uh any Unity version if you want I'm not going to expect you to follow along during class um it's mostly for the assignments afterwards but if you want you can follow along but I'm not going to design it for that I'm going to kind of just steam ahead uh just to give things a little bit more efficient um okay um but again my goal here is to make you learn if all of this is something you already know it's fine if you kind of tune out a little bit like I don't want to force you to do something you don't need to right um and again ask ask questions please ask questions every time someone asks a question and they're like oh this might be a dumb question but it's a very good question and so please ask questions that like I'm I'm not infallible there's quite often I will miss things or misspeak and and so just always ask questions if something's unclear um you students you have your Discord chat so please just type things in there um and I will I will read it I'm used to reading while streaming so um okay all right um any questions so far people are typing so I'm gonna have some tea it's okay to ask a question even though I might know the answer just to share with others um yeah sure um you can do that um yep why not it's the best um not sure if I read this somewhere you said it last year's recording but you said we should use Unity well will we get feedback on what we do from you and if so what Unity version should we download um I I recommend using Unity uh 2021.2 or later um but you can use anything like 2019 or later it doesn't really matter we're not going to do any like super like complicated like Unity version specific stuff and so you can use whichever one I just prefer using 2021.2 and onwards because you get newer c-sharp features um yeah uh I understand the concepts by placing the logic in the right order of something new to me encoding I find it to be difficult uh yeah we're not going to be doing that much coding uh we're going to do it but it's mostly going to be for the assignments and to like Show an example of whatever it is we're talking about so it's mostly going to be focused on math rather than code but we will do do code so um yeah um will we be learning calculus concepts are mostly algebra um So the plan is for me to do the first week the way that I usually do my math course and then the second week I'm thinking we can kind of do um whatever you feel like doing or like what you would like to learn um or I can just come up with some Concepts if you don't have any ideas um and so calculus is not I don't know someone's probably gonna on me for this but calculus is not that useful in Game Dev you pretty rarely bump into calculus and so it's not my priority but we can talk about it if you want to but it's probably going to be like during the second week if you want to talk about that um that's not to say that it's useless it certainly is useful um but it's it's less so than the concepts we're going to talk about before then so we're going to start out with linear algebra because that is one of the most fundamental and important aspects of the math that you use for gametev my experience when I took math 2 last year was that I could understand the concept and practice of math equations and methods if I struggle figuring out which ones to use and how to use them in real life examples yes I'm going to try to use them in as many real life examples as possible just to kind of ground it in reality where reality is game development um okay and people in chat are saying that game of physics uses calculus a lot yes but most people when making games these days don't write their own physics engines uh generally most of that is handled by uh the engine itself you might use some calculus if you if you you write your own trajectory code or if you're writing splines but quite often a lot of people don't really do that themselves um and so linear algebra and trigonometry and that kind of stuff is more important okay uh any other thoughts can we survive in the industry without learning math um no you have to know a certain amount of math um I think if you are a game programmer and you don't know some amount of vector math you will struggle a lot um but that's why I'm here so that I can teach you how to how to think about it how to use it how it works all that kind of stuff so so hopefully hopefully you will learn it after after these few lectures okay all right Vector Math is Fun matrices not so much um we're gonna talk a little bit about matrices but usually or generally we're just going to limit matrices to to the specific use case of transformation matrices um because that is that is like the the one place where you're going to frequently bump into them um but matrices outside of transformation matrices are very rare in-game developments okay all right uh how's my mic by the way I feel like I I'm not sure if it's good because a cat dropped my preamp to the floor so I don't have my compressor chain and I have no idea what I sound like right now it's good okay good um okay cool um any chance to see Cats yes where are they well there's only one cat right now uh that white blob over there that's salad so I said there you go that's that's one guy okay but yeah there might be cats in the background running about um we have three cats so there's either gonna be me a white one or a black one or a seal a brown one from your past lectures I find your cat to be a little distracting I don't know what to do about that people say that but it's like I can't just tell my cat not to meow like I don't know I can't shut them into the bathroom I there's I can't do anything about it okay excuse me um all right so um I think we're ready to get started so I think one uh pretty fundamental question uh that I think we should like ask ourselves whenever we study something it's always good to ask why like why why would we study this topic and like why why would this be a useful thing to know right uh when you're in school quite often you're kind of just learning because you have to but in this case you're learning because it's useful right um and so I think the um for me one of the things I really like about math is that this is just kind of my perspective I don't know if you're gonna agree but I think math is super fascinating because no matter where you are this is a field of study um like even if you are like in some other Universe on some other planet maybe you're in a universe with different laws of physics math exists there there is the study of math as long as there's intelligent beings I suppose math will exist it's kind of inescapable and I think that is really fascinating because math is so fundamental that it's kind of the study of quantity the study of space of structure and of change and it's kind of hard to imagine a universe without those things right and so so I think it's kind of cool that like any Discovery you make in math can be made independently literally anywhere else um and so like the the concept of like the circle constant or the value of like e the golden ratio like all of these things can be co-discovered everywhere which I think is super cool um and so it kind of underpins everything in physics chemistry and biology um so it's very similar to philosophy in that sense that it's kind of the the um the foundation that so much stands on like you can't do morality or ethics or politics without philosophy um and so I feel like math is sort of a similar similar thing when it comes to like the physical world um and so it's kind of this like universal language that can describe any world and any world of course includes Virtual Worlds so we make worlds that we try to replicate our own world or slightly different worlds but these worlds still follow rules that um that exist in math um and so so that's why I think math is cool not only because it's useful but also because of this like universality of math which is which I think is neat um and so so I think apart from the usefulness of it I think that that's a good reason to study it because it's kind of it's fascinating you know um okay all right but we're going to start at the basics we're basically going to Speed Run math from when you started learning math probably until somewhere in high school um that's what we're gonna do um I just need to open create a new document um is learning math beneficial in other areas for programming industry not just the games industry uh yes but it's going to depend on the domain like if you're if you're doing programming and you're working with like architecture or if you're programming and working with like statistics the kinds of math you're going to learn is going to be different um and so it kind of depends on the domain but it's generally generally it's going to be useful right um and it's it's not like I think quite often anything you learn in math will sometimes turn out to be useful eventually given enough time but of course sometimes you want to try to focus on the things that are most effective in the moment to focus on right okay all right uh I'm gonna try to take one break for every hour so we're gonna do a short like maybe five five minute break 10 minute break just so you can go to the bathroom and stretch your legs and whatnot or get some tea um so so if if I forget to do a break feel free to let me know because I sometimes forget uh are there any other other areas of math you recommend us looking into they won't go into this course that depends on what we're going to do the second week I have a plan for the first week the second week I want to leave open and kind of improvise depending on what you want to talk about and so what I recommend depends on what we'll already cover and and so yeah there are many areas you can look into like an Endless Sea of things okay all right I got my notes um okay oh and the sorry YouTube chat I'm gonna ignore you until we get to breaks because I'm focusing on my students at future games and there's more information in the description if you have questions okay where is my hell yeah we didn't um I guess if we want to write down second week I DSS would go and then we can bring them up at the end rather than it's finally a second week idea um yeah you can always ask questions about anything during the lectures but if you're asking something that might be a little bit too off topic I don't want to go too far into attention um and so yeah um but yeah feel free to keep a mental mental notes on things you want to talk about and then we can then we can do that the second week how many weeks is this course two weeks we have I plan for three lectures uh per week uh although this one is going to be cut short because you had other things scheduled um so but yeah it's gonna be about three lectures per week and we might do uh focus a little bit more on working on assignments the second week but yeah the first week is going to be lecture focused and assignments I'm going to do assignments after every lecture but they're going to be pretty small you'll have shaders later yes okay my monitor is very very dusty um so apparently some some some group of students have something scheduled after lunch but not all students I'm a little bit confused that some sort of retrospective for the thing um okay not on the Stockholm people have things scheduled okay and so I will I will move those hours that you're missing out on to a different different day because I don't want you all to miss out on on hours so so don't worry about that okay all right let's get started let's get into let's get into the the basics let's talk about numbers I think you're pretty familiar with those at this point um but we we should cover them anyway because they're very useful um so if you have let's see I hopefully hopefully you talked about this concept called a number line uh where you can sort of imagine this line where you can place all numbers on so you have zero uh we have one two three four Etc um and then on the other end you have the negative numbers you have negative one I'm sorry for my handwriting it's kind of bad um but it's hopefully readable okay so the basic number line is kind of like this this line where we can place all numbers that we um that we use right and so these numbers are often called the ones you see here that are whole numbers are usually called integers um so that's whole numbers and then any numbers in between um are going to be have like a decimal point so between two and three we have two point two point five so that's halfway between two and three uh and so so this line kind of contains uh all um all real numbers so this is also called a real number line um and and so when you think about numbers I think it's good to think about them as kind of like a position along this line right and so you can sort of conceptualize the the number two you can sort of think of two as an offset from zero and you can even draw that as an arrow if you want to and so this Arrow sort of represents the number two or the position two um or you can do the same thing for negative one maybe you can draw that as an arrow as well and so this would be negative one and this would be two um and so the um so whenever you you think about what numbers are and how to use them then it kind of depends on the context so if you're um if you're using these as positions then you can you can manipulate these and add them together and like a reason about them so this is the position of an object so let's say maybe have a a player character standing here um then we can represent their position using a number right if we change the number we change the position of the the player um so this is a very one-dimensional game it's kind of flat but we can still still use the um use these numbers to represent things so for instance if we want to know how far away is the player from four for instance that is a question we can ask that actually makes sense and something we can calculate and so so let's first like draw the value four we can draw that as an arrow as well uh so if we want to get the the distance between two and four I'm sure many of you are familiar with this this concept of checking the the distance between two values but then we would generally do something like four um minus two so if we take this Vector but we cut off or this arrow and then we cut off this part then we get the the distance between um two and four right so four minus two that gives us two and two is the the distance between here from the player to um the value of four right um okay so that's just kind of like the the basics of number manipulation you can you can just kind of uh subtract to get the difference between two values uh then you can also add them to to get the to get offsets um so so maybe you have like some some object that's floating around uh behind the player or something maybe have a maybe have a camera that's following the player so maybe maybe this is a camera and you want to place this camera relative to the player so let's say the player is moving then you want the camera to follow the player so then you can set the camera position based on the player position so maybe you do player position plus some offset so maybe you want the camera to be like one unit away from the player then the camera position would then be player position two plus one and then you get the position of the camera uh and so I I think it's good to think of numbers as things you can manipulate relative to each other measure against each other and sort of think about them spatially um as existing in this along this line I just need to go open a window because it's really warm in here for some reason and so I'll I'll be right back thank you very warm okay um so um so we can sort of sort of make up some rules that can be useful um and so so first we have the the rule of addition like we can add add these together so we can add numbers together to to offset them we can also scale things if we multiply them um so that's kind of the two operations that we usually work with um okay uh let's see just need to erase things because it's getting a little a little messy I'm Gonna Keep the player I don't know if we keep the player Okay so um so we can already like write some some useful rules when working with numbers um so so let's say we want to write a general rule to get the distance between two numbers um and so let's say we have a number um a and then we have a number uh B and we want to get the distance between these two uh so let's say we write um so if you want to get the distance between a and b how would we do this well like I mentioned before we can subtract things to get it get the difference like we did before um so so if a is the character here let's see that that's the value of a and then we have B is the value here and we want to get the distance between these two so the distance would represent the um the number that represents the distance between these two right um and so the thing we did before is that we did B minus a um but if B is instead of instead of being here it would be on the other side so maybe B is here then our distance is going to be negative and generally distances are not negative because again if we're doing the same thing here of B minus a um we're going to do one so the value of 1 and then minus 2. so I'm going to do minus 2 we're not going to add it but instead we're going to flip it to the other side because we're subtracting it and then if we sort of take these two stack them on top of each other it ends up pointing back to negative one so now that we measure the distance it says negative one when you when it's possible to get a negative distance that's called a signed distance um so signed as in signed so assigned distance just means that the distance can be negative depending on some conditions but usually when you say just distance you wanted to always be positive so it can only be negative if it's assigned a distance and sine is referring to the um the sign of the values either plus or minus right so that's what that's what sine means um and so so we want some way to get the distance between these two but maybe we don't want it to be negative uh then we can use a function called the absolute value um so in code you would generally call a function called abs of some value X or maybe we should call it a just to be consistent um so the absolute value of a mathematically you would write that with vertical bars so you would have a vertical bar and then a vertical bar the absolute value kind of gets you the length of the arrows that we were drawing so if we get the absolute value of one then that's going to give us one because the length of this is one uh the length of a is 2. um so that doesn't seem surprising but if we go to the negative values like if we have another Vector that goes to negative three then the absolute value of this is three it's not negative three so ABS the absolute value function basically turns negative values into positive values um so that's what the absolute value function does so if we want to get the the distance between two objects and we don't want to have negative values we can use the absolute value to make sure that we don't get that right uh and so what we then do is we get the absolute value of B minus a and so this is how we get the distance between two numbers um and so whenever you want to compare two things see how far away things are from each other then you can use this distance function uh uh okay and then relatedly let me just move things around and again just let me know if you have any questions at any moment and I will be happy to answer them um oh I also missed a question um can we also manipulate vectors through the transform component like placing camera behind the player yes we're gonna get to that [Music] um so better to use the built-in distance function or calculate it ourselves uh we're going to get to that too um the answer is that it kind of depends uh okay I didn't miss any more questions um okay so now a way to get the the distance between two numbers um so we have the um the distance is just a positive distance between two values we can get the distance between like negative three and two and we will get a value of five because that's the distance between between these two no matter what order we would check it in we're still going to get a positive value as long as we do the absolute value of this difference right um we're gonna get to Vector soon don't worry this is this is this is a convoluted way to get to vectors um all right and so another property we might be interested in um is sorry I need to drink please remind me to drink [Music] um my voice tends to get very coarse the longer I go on um okay so so now we know how to get the the distance between two values uh we know how to get the absolute value or the the kind of the length or the magnitude of a value but there's another property that can be super useful sometimes you have numbers that can be well on either side of the the number line of course like some values are negative some values are positive but sometimes it can be useful to get the sign of a value and the sign of a value is kind of like it kind of tells you what direction it's pointing in um and so if we have another value C over here then C is pointing in this direction but B is pointing in this direction right and then a is pointing in the same direction as B um and so so one thing you can do to figure out what side of something is on you can use another function that is called just the sine function so s i g n not s-i-n that's for later um so the sine of the value so that gives you the the direction um basically so is it positive or is it negative and the direction is going to represented using values of either negative one or one um and if you want to get the the direction of some value um then the kind of like algebraically how you figure that out I just need to move this because I I don't know I don't know how to fit things in um and so algebraically how you get the direction like let's say you have the value of c b and a and you want to pass it into a function and you want to get the direction out of it so C should be negative one B should give you one and a should also give you one because that's the kind of the the the unit vectors the unit directions that that we the the two directions that we have right and the way to do that is you take the value of a and then you divide it by the absolute value of a so you basically divide it by the length of it um and so that gives you the the sign so so that if whatever value you pass in you're gonna get either negative one or one um and then if you uh there's a special case if you're passing in zero because as as you probably heard dividing by zero is generally undefined in math um and so dividing by zero is usually a bad time and so the the sine function usually has a special case where if a is zero it either returns zero or one uh usually the mathematical sine function always returns uh zero for for zero but then for some functions and some math libraries depending on what you're using it might return uh one for zero so it really depends but usually it will return zero in any case it's always defined at zero um okay did that did that make sense so far any are there any questions uh everything until the very last part was sign okay so if you have a so if we want to get the the sign of some value so let's say we want to try the value 2. um so when the divide that by the absolute value of 2 um then this is effectively it's x divided by X right because the absolute value of 2 is 2. so this is going to be this is the equivalent to 1 divided by 1 which is one right um if you have a negative value so if we have negative 3 and then we divide that by the absolute value of negative three then what's going to happen is that the absolute value here is going to be equivalent to 3. so we get negative 3 divided by 3. which is equivalent to negative 1 divided by one which is equivalent to negative one there's a lot of lines here sorry about that um so we get negative one um and so effectively what the sine function does is negative values give you negative one positive values give you one and zero gives you zero so and that's kind of just how it's defined it's just we just decide that that's how it works right and you you can implement it using the a division but sometimes you just do it as an if statement like if it's greater than zero return one if it's less than zero return negative one if it's zero return zero so that's that's quite often the the way you you just implement it but if you want to do algebraically this is how you would do it yes all of these are built-in math functions that is that is true uh where would you want a number to be simplified to one or negative one um so quite often when you measure things in games you get a floating Point number as in a value that could be any number either negative or positive doesn't have to be integers and so quite often you want to check which side of something you are on um so so let's say that maybe we're looking top down on a um maybe it's a car in a game so let's imagine this is the center point of a a car that is just a box um and so this maybe this car is moving forward and then you want to know maybe you're writing an AI for a car and you want to know which side which direction should it turn if an object is here or which direction should it turn if an object is here or here and so forth and and so so that's one case where you can use the sign to know which side of the car is the object on uh given a value for the the relative position of some objects right um and so you can sort of use that to determine she would turn left or she would turn right um so that's that's a use case for the for the sign so generally it's used for which side of zero is it on um and then that has various use cases like that okay uh oh each bomber guy in chat hello I also can't wait to watch this when I wake up uh I guess we're going into this later but how would that look with the relative position and not zero is the point uh we're gonna do that later um that's gonna be um yeah that's gonna be later we're gonna get into that because that involves more advanced things that we're going to talk about soon um okay cool how are we doing on break by the way I've completely forgotten time uh uh okay do you want to do 10 minute break or a five minute break vote in student chat maybe I should clean this up uh ten five four five five five five five five five five five okay uh 29 uh uh okay I think I think the consensus is fine so we're gonna go for five minutes more and then we're gonna take a five minute break um okay let's I need to bring up my notes um okay we're actually at a really good break point right now okay we should probably do a 10 minute break then um or we could do the five minute break now but then we have a weird we don't have a natural point to end the break if we do the five minute break now um okay let's do a 10 minute break let's resume at at the 10 o'clock um I'm still gonna be here or actually I'm gonna make some teeth but other than that I'm gonna I'm gonna I'm gonna be here during the break okay I'll be right back [Music] foreign just hopped onto the stream and I walk away oh yep that's that's why okay how's the YouTube chat doing any tips on Cheaters uh watch my Shader course on on my channel that's my tip it's a very general question so will this be uploaded to YouTube yes all of this is gonna stay on YouTube after after the whole the whole thing is done so yes um do you have a schedule for the other lessons uh they're gonna be tomorrow and on Friday are your twitch overlay is still on oh yeah I should probably not have that thanks [Music] tomorrow and Friday what about Thursday um I don't I didn't initially plan to do anything on Thursday so Thursday was going to be just a work on your own I'm gonna give you an assignment and then you work on it on Thursday when should we use magnitude versus Square magnitude um I'm gonna get into that later but effectively Square magnitude is used when you're comparing just comparing distances if something is closer or farther away than some threshold then you can use squared magnitude because you don't need to know the actual magnitude you just need to know if something is less than or greater than a square magnitude is much faster to calculate and so it's it's usually an optimization um but we're gonna get into that later so that's spoilers so we shouldn't talk about that now how dare you spoil things jeez e okay my tea my tea is ready so I'm gonna go get the tea foreign foreign that's great nice I'm I'm happy already water that's a good point I need water I'm gonna go get water foreign huh I used to suck at square roots it's convincing to know the computer suck at it too yeah okay let's see I got four more minutes of break YouTube chat do you have any do you have any questions before I disappear into the Discord chat of the students uh a friend that we explained math extremely intuitive any chances of something like this but aimed at a younger audience um I've never considered that usually my audience is game developers like people who know how to code but forgot all a mess that's my very specific target audience um um yeah I don't I don't really I haven't thought about that um yeah I'm not sure wait are there people are there future game students that haven't that are not in the student discard uh they're like five different servers that's true I don't really know how all of this works it's the one called fg22 Dash ftgp you don't have that one uh are there any students in fg22 that can invite a tour I don't know if I have invite permissions okay you're doing the unwrite it's good you don't have any white permissions either but I'm guessing there's someone has to have it at least the class representatives I'm hoping guessing what do I need to do I'm getting people in YouTube chat who say they are fg22 students who haven't gotten an invite to This Server um looks like you did I don't know how to pronounce your name you did I think you're you're on it uh the Third cheat sheet for those useful math functions um maybe um I usually like save the all of my notes that I draw during my math class so I could send that probably gonna post that on Twitter at some point are we going to touch upon imaginary numbers maybe with quaternions um I don't have any plans to but I could again the second week we can slot things in if you want me to talk about stuff um and so I could but it's up to you really because imaginary numbers are rarely used in games but if you want me to talk about it we can do that the second week okay um should we continue or do we need more time I don't know what's what's going on with Ian whites okay you got the invite sent that okay uh one thing about the um I don't know how to vet the YouTube chat I don't know who's an actual future game students or if someone just wants in on the future game server um okay you're here now okay it looks like a lot of students on the credential site didn't get an invite to This Server I think I think that's what's going on right okay we're zooming as soon as this is a result okay T thank you foreign let's continue I'm guessing you're all back are you all back are y'all ready to continue or did we all zone out and we might be missing one person still oh now they're in okay are we ready to ready to resume I think we got everyone in who needs to get in right was it just two people I think it was those two people as far as We Know okay all right um let's resume there we go react to that if you're present and then we're gonna get started cool foreign messages are so good because like all the introverts they don't have to type anything they can just click click a button and then then it's done okay all right let's see I'm gonna Shuffle things around a bit okay interacting with the UI in Photoshop using a tablet is a really really inconsistent and weird I don't know why it's really annoying okay so I've been talking about numbers up until this point um although I'm sort of interpreting them as arrows and this kind of interpretation is usually something you reserve for doing for vectors so we're going to talk about vectors now and so the idea of having a number line like this where you assign a value to each position along a specific line we can extend this idea to two Dimensions instead of just one and so we're gonna we're gonna add another number line that is going to be perpendicular to the the first I merge that too early oh no oh geez my desk is messy um so now we've taken the same number line and we've created a new one um that is perpendicular and we're going to give these some names so let's merge those there we go okay the layers of these lectures tend to get very messy after the lecture is done all right so now we have another number line and so this one is perpendicular to the first one and this one also has numbers so we're just going to do the same thing we have numbers one two three actually let's do the other side one two three um four Etc and then a negative one negative two negative three and negative four and so now what we've done here is that we've created a coordinate system that has two axes and so this axis is called the x-axis and then this one is called a y-axis and so instead of just one number line we have two of them and so just like we could determine a position along this line like you know the player has a position and we could we could represent the position using a number um for this one we can represent position for using two numbers so we're going to have two numbers where each number is associated with each axis so for example if you want to represent this coordinate like this point we can do it do that using two numbers so when we use two numbers we usually write it in parentheses like this um and so if we now look at the the number line so you can see that this one is aligned with two on the y-axis and it's aligned with 3 on the x-axis well kind of assuming I drew this perfectly um and so the way they represents this position is using two numbers so that's going to be three and two and so this right here is a vector and quite often we we represent them using arrows like this so just like we did for the for the numbers or the the scalars so these are scalars or numbers or values or real numbers we can do the same thing using vectors where you have two numbers and they together represent a position um and so these are absolutely fundamental everywhere in games vectors are used to represent positions in space it's used to represent directions it's used to represent relative offsets it's used to represent velocity it's used for like absolutely everything so the concept of vectors is extremely ubiquitous and so that's why we're gonna we're gonna talk about vectors and again this can represent any coordinate in space it doesn't even have to be integers it can be like halfway between three and four but the the general concept is that you have two numbers where the first one is the x coordinate and the second one is the y-coordinate and it tells you where you are along that axis um and so just to do another example uh we can do another one that is maybe here and so this vector would be on x coordinate negative 4. and a y coordinate of one um okay and again we can we can represent this using vectors if we want to um so we can draw draw it as an arrow like this you don't always draw them as arrows sometimes you draw them as points kind of sometimes it depends on use case but it's just one way of visualizing it um okay did that make sense so far because this is incredibly important to to have a have a clean grasp on and to understand uh because again this is ubiquitous in thinkings um so so did that make sense this is basic math in high school yes that is true and I'm trying to go through all of high school well not all of high school but the select important things in high school just to make sure that everyone is caught up and on the same page right and a lot of people forget math people aren't typing um how would you go about making non-euclidean vectors um I I haven't really worked with non-euclidean vectors but I'm guessing it's just a matter of interpretation like how you interpret the the two numbers in the Tuple and how you operate with them right it's going to be different depending on the non-euclidean space but um [Music] okay all right I'm guessing this is cleared so far so we're gonna continue um okay and so when you have vectors like this uh just like how we had arrows or numbers we can add them together um so if you want to do a plus b then we basically take this arrow and stack it on top of a and the new position we end up with here is then three because the value of B is a one the value of a is two and if we add one on top of it on top of two we get three two plus one is three you imagine that and so we can do the same thing for vectors so we can we can take the the arrow of one vector so let's do this one um and maybe not take everything with us and then we stack it on top of the other one and then we add them together and then we end up with a new vector that is going to be at this location here so if this is a vector maybe we should color code this so if this is Vector a and this is Vector B then adding a plus b gives us this coordinate right here um and so we can call this vector C and so C in this case is a plus b and so C equals a Plus B and when we add vectors together like this we basically just add the numbers in each component so C in this case is going to be negative four plus three so that's on the x-axis that's going to be negative one and on the y-axis we have one plus two and that's three so now we've added these vectors together so that's that's vector addition is very straightforward uh you take them just add them together component by component and this is what we get um so do do [Music] all right so that's Vector Edition uh subtraction Works in a very similar way and subtraction is particularly useful um I hope this made sense by the way how how we got C from A and B um okay and then subtraction is very similar um where you still do it component wise and it's effectively like adding the negated version of some vector so let's say we want to calculate a minus B um so we have a minus B and so that's going to be I guess we're going to find a new Vector let's call it d so if we want to do subtraction then uh one thing that's really useful to keep in mind is that subtraction is basically always the same as adding the negated version of some other number right um so if you do like five minus three that's a bad number five minus four uh this is the same thing as five plus negative four and so vector addition we can use vector addition to interpret this so we just need to know how to negate vectors and negating vectors as in flipping them or just turning just changing the sign of them you do that component wise as well so if we want to do a minus B we can just figure out minus B and so minus B is just reflecting this B Vector to the other side um and so we're going to get the vector all the way to here so this vector is negative B and then we add those together so now we can add a plus negative B so we have negative B over here and then we add that to a and so we're going to end up again we take this Vector place it on the edge of this vector and we're going to end up outside of our number line because I don't know how to plan um so effectively we're going to end up at let's see four plus three that's going to be very far away it's going to be at like seven somewhere around six and then we have seven so we're going to be here and down one so here's our here's our new vector going between here so this is our Vector uh d okay so D is now a minus B um and one way you can um wait is this right I feel like I I feel like I missed something uh yeah so D is from zero um but I feel like I did something wrong hold on oh yeah it's from zero sorry that's why I thought I did something wrong that's the position we get so that's correct but the vector should be drawn from zero not relative to a this long Vector right here that's D thank you okay so this Vector d uh it might look a little weird to put it here but effectively when we do uh a minus B this Vector is the same as the vector from B to a so if we draw this line here between these two it's getting a little cluttered sorry about that so this long Vector is also d um and so what we basically get is the difference between these two positions um and so so one way you can interpret this when you do a minus B that is effectively um like colloquially and in language it would be like um the vector from B to a so that's that's what you get from this and this is a very useful thing to keep in mind uh because you you quite often use relative vectors like this um when you want to know some offset or displacement between two coordinates right um so this is kind of the the difference between two vectors um a minus B is not the same as B minus a right yes um the um that is not the same thing and that's the same for numbers like um it's the same thing for numbers B minus a a minus B don't give you the same results um so those are different um in math language I think that means that they're non-commutative I think I sometimes mix them up but but subtraction is non-commutative but addition is [Music] um Okay so now that we have the um let's see maybe I should clean this up a little bit let's remove C we don't need c anymore I'm sorry see but you were useful while you while you lasted um okay so the um maybe I should also sorry about the screaming kids in the background I think there's like a kindergarten somewhere here and so if someone is screaming it's not my fault I don't know why kids scream so much it's kind of kind of obnoxious huh okay uh let's actually erase this one too I don't really need this don't need that you don't hear anything okay good all right so um D is is now the again we get the the vector from B to a and this is kind of a bit of a cursed thing because quite often it's easy to mix these up like quite often when you do math it's easy to think that this is the vector from A to B but this is from B to a so it's a little bit reversed um it's something something to keep in mind whenever you're doing this and the and flipping these two actually gives you a different Vector that gives you the negated version of this as in you get the vector going from A to B if you flip them so then you would get this vector right here so this would be negative negative d um okay uh it's also worth keeping in mind sometimes vectors are points and sometimes they're directions um yeah it kind of this is a matter of interpretations uh interpretation because like inherently vectors aren't anything it's all just what we interpret them to be and that's not really like encoded in the data type itself it's always just numbers but if we use those numbers to represent a velocity or if it's a position or a local space offset or maybe it's a color like it could be anything we can use them to represent a whole host of things right it doesn't have to be anything in particular but the the vectors themselves have no knowledge of space or context and you'll you just have to keep that in mind and remember it I usually recommend naming your vectors after what they are so if it's a position make sure to make that clear that this is a position relative to some Center of some space if it's a local position make that clear in the variable name if it's a a direction then just make that clear just to make sure that you you know what the purpose of this Vector is and how you got there and the context it's supposed to be used in it's very useful to keep in mind because you can often get confused and forget how how and what things are um so for instance this Vector D is kind of this is a relative Vector it's a vector sort of relative to B the way that we interpret it now right but the numbers themselves just represent you know this Vector going from zero but there's no difference between this and this we're just drawing them at different locations but they have the same values in the vector um and so that's a good thing to keep in mind uh vectors don't have an origin they only have their two numbers uh so you don't have a start and an end you only have the end point and so D here we're just interpreting d as something relative to B right um okay all right I hope that made sense um we're gonna move things around a little bit what Photoshop let me let me move things thanks okay so now I should probably clean this up actually let's duplicate it cleansly all right um wait where'd my numbers go oh no I lost we've lost the numbers oh geez oh no I'm sorry I was a real awkward I can feel my my ratings drop my students are judging me so hard right now oh geez okay there we go um will you upload the slide uh yes I can send you this whole document once it's uh once we're done uh why do we go all the way to five here but only to four there that's a mystery um Okay so stop Photoshop behave all right so um if we then want to again like we did here with the player we can get the distance from uh between two things right we have the player uh and then maybe some objects uh maybe it's a it's it's a box that's how creative we're gonna be it's a box so we we want to know the the distance to some box then again we can use this this function here where we take the difference between the two numbers um and then you get the absolute value of that so we get the length of the vector between these two objects and in this case the uh which order you do it in doesn't matter because the length of these two vectors are the same right uh and so if we want to translate this into two Dimensions things get a little bit more complicated but still very similar so let's say you have a vector here so let's color code this one to start um so we have this Vector here so this is a and then let's do another vector we're going to do this is our Vector B um now if we want to get the distance between these two then what we really want again if we look at look at the way we did it for numbers we get the difference between them and then get the length of that right and we can do the same for the vectors just like we did before we can subtract these two to get the vector representing the displacement from one to the other right or the difference between the two um so that gives you the the vector just subtracting those two numbers so um that gives you oh boy actually let's do it in white drawing straight lines is very hard I'm sorry still working on my artist chops okay imagine these are overlapping uh so so this gives us the the difference between the two so in this case uh this would be B minus a right like that's this white vector now if we want to get the length of this this vector [Music] um things get a little bit more complicated we can't just do the absolute value like this so we have to do um we have to do something a little bit more special than that and you might remember from from math class and when you were in high school you talked a lot about triangles right I'm guessing you remember this you had a triangle um and then you had some side lengths um so you had the the hypotenuse and then then you have some some I forget the names of these usually it's like the opposite but we're not doing angles let's just call them ABC uh so we have a we have B and we have C right um and we actually have a very similar situation here if we want to know the length of a vector what's really happening here is that we can we can draw this triangle right so we have a triangle with a 90 degree angle and so this just boils down to the Pythagorean theorem we just uh you probably remember that one right there you go um uh let's color code this you think you remember it that's fine I'll repeat it don't worry okay so the Pythagorean theorem um is is kind of a straightforward way of knowing the length of C so in this case if we have these two um these two lengths we can figure out the length of C using a pretty straightforward relationship um so if we have C squared is equal to um a squared Plus B squared so this is the the relationship of the Pythagorean theorem between all these three sides and so we can then Shuffle this around in order to figure out the length of c and so we can just copy this um and so if we take the square root of both sides we cancel out the um the power of 2 here so we're gonna delete that and then we'll move that over and then then magically we now have a a square root of this and and that's how that's how you can get the length of a vector I I had it organizing this layout I'm sorry okay um and so in our case uh we have a very similar situation right again if we want to know the length of a vector the vector has X components and Y components um so this Vector B minus a if we draw it from the origin we can have something like this right um and so this two will form a triangle the the triangle will have the side lengths of X in this case four and Y in this case negative 1. and so really what we're looking for to get the length of a vector is we're doing x squared Plus um y squared gives us the length of a vector where X and Y is the components of the vector um again the the components of a vector would simply be X and y so that gives us the length um because I need more space Oh no um was this lecture till 12. uh yes because then we have lunch and then everyone except Stockholm has a retrospective thing after lunch so I'm going to give you an assignment to work on okay so this is how we can figure out the length of a vector um okay and this is sometimes also called magnitude of a vector so you're going to find those words used interchangeably so this is also known as magnitude all right so now that we know the the magnitude or or length of a vector we can then we can then figure out the distance between two points so you kind of always start with length as your your starting point um again the same thing we did with numbers the absolute value gives you the length of the length of a number so negative 6 has a length of six um and then using the concept of the absolute value or the magnitude um we can then get the difference between two numbers and then get the magnitude of that difference and that is what distance is and so we can do the same thing for vectors um so if we want to get the distance between two vectors um let's call them A and B um so that is going to be the length of the difference between the two and the difference is going to be B minus a and then in order for us to get the length we have there's a shortcut to denote the magnitude which is two vertical bars like this and so these two vertical bars means this you you get the the length of the vector itself um and so that's that's what those two vertical bars mean and you can probably see that there's a very very striking similarity between just numbers and vectors um because you're effectively doing the same thing except the distance calculation is a little bit different um but you could use the uh the same structure as the Pythagorean theorem even for the one-dimensional case okay does that make sense or was that a bunch of gibberish okay so that that is the distance between a and b oh yeah this this is flipped that's flipped oh no literally unplayable see it's easy to mix it up it happened in real time um yeah Adam I think that was the issue right because I had it flipped Ariana should land somewhere else not at Forum because I didn't draw this to scale so it should be um go further than that there we go it's mostly for visual purposes don't read into this too much you know there are flaws there we go um okay and so uh just making sure we got time the the next thing we might want to do after this um is uh check out for the sign like remember we we had a way to check the direction of where this was headed like we can see what side of zero uh each number is um and for uh for just numbers it's it's a very straightforward a way to figure that out if it's greater than zero the direction is one this is less than zero the direction is negative one if it's zero then in math we usually just Define it as zero even though that's not really a direction um so but but in in 2D things get a little a little spicier than that um I'm going to remove this maybe I'll remove this too Maybe we don't need this one anymore it's refreshing to see me make mistakes yep I don't make mistakes when I'm not streaming I promise I'm I'm Flawless whenever I'm not streaming it's just because of the public pressure you know um okay and so if we want to get the the direction of a vector then in this case the answer is not just negative one or one right um like sure we can sort of do it per axis if we want to but when we do this with Direction vectors or when we want to get the direction of a vector what we're really asking is what is the vector that is pointing in the same direction as original Vector but with a length of one so around the origin here we have a circle that passes through one ideally on all of the axes this is a Flawless picture there we go um and so this circle represents all the vectors with a length of one right so no matter where we go on the circle all of these vectors the magnitude of them is exactly one um and so again if we do this equation this length on this circle all of them is going to be exactly one these vectors have a special name the vectors that have a length of exactly one are called unit vectors sometimes they're called normalized vectors yeah normalized vectors are unit vectors and so this circle is called the unit circle um and normalized vectors are very very special they're very useful and you're going to see them almost ubiquitous in many cases normalized vectors are special because if they have a length of one so let's see the length of this one is exactly one if you multiply this vector by a number let's say you multiply it by five it's going to create a vector that is exactly five times as long and so if you multiply it you're going to basically stretch this one to become longer and so this one would have a length of five if you multiply it by five and so normalized vectors are usually used to represent directions um so quite often when you see the word direction it's often implied that it has a length of one um so if you're using something in unity like transform Direction then that is going to imply that you're dealing with normalized vectors and so so normalized vectors are very very common you see them in many different places in Game Dev and so it might be useful how do we get a normalized vector from an arbitrary vector and effectively what that is is we're doing the same thing we did um here with our numbers if we want to get the direction if it's positive or negative we can take the value and divide it by the length of that value and for vectors it's exactly the same thing so if we want to get the direction of some vector then the process of doing that is called normalization so it's kind of the direction slash nor oh geez the normalized function um other some Vector a it's hard to pick the correct brush size then we do the same thing we take the Vector a and we divide it by the length of a and there we go so this is exactly the same thing as for one-dimensional numbers we take the the vector divided by the length of that vector and what's going to happen is that we get a unit Vector out of it so if we normalize this Vector a what's going to end up happening is that we get this Vector right here and so this is a normalized so vertical bars uh a I need to add presets to to select brush sizes I feel like because it's always too thick or too thin there you go normalized a that's the process of normalization um so effectively you're turning a an arbitrary Vector to a um arbitrary Vector to a direction like what is the direction of a then we normalize it and we kind of get the the direction Vector which is also known as a unit Vector because it has a length of one uh uh okay [Music] um just checking for questions uh it's okay to have a little bit of off-topic conversation but just don't fill the entire page especially if there's a question then I don't want that question to disappear uh okay what would happen if you use a non-normalized vector for direction a lot of assumptions will break that's kind of the problem there's there's some other situations as well where normalized vectors matter and we're going to get to that right after this um okay any questions so far did did the concept of normalized vectors make sense non-normalized vectors will be used as a speedrun strat uh I believe this is the basis for uh bunny hopping and a lot of FPS games um where there's a vector that isn't normalized and it's slightly off and therefore you can build up speed uh distance a b didn't quite stick um right so distance um if we want to get the distance between two points or vectors we have a point a and a point B and we're just drawing them as arrows um then effectively what we're doing is that we're taking the vector between the two this Vector right here so this is the difference between a and b so in this case this would be a minus B so we're taking that vector and getting the length of that Vector right um that Vector itself is B minus a or a minus B and then it's going to point in the other direction right so now that we then have that Vector B minus a um we just need to get the length of that one in order to um in order to figure out the distance between A and B so really what the problem boils down to is two problems one finding this Vector which is a minus B and two getting the length of that Vector which is the same length function we would use for any other Vector right um and that is this length function right here which is we're basically taking the components of the vector the x coordinate and the y coordinate we're squaring them adding them up and then taking the square root of that and that gives us the length of that vector um is there a term for a vector which fits inside a square instead of a circle uh yes that is then you're using a different distance Norm um so if you want to read up on this you can look up the concept of I think it's chebyshev distance you're talking about um so chebyshev distance is a different type of distance Norm uh then we're not using this as our way of measuring distances anymore this is a special case called euclidean distance um so chebyshev distance would be this square right here and that's used for stuff like if you're making a board game then maybe you want the diagonals to count uh as uh one if if you have a grid movement in a game for instance um then maybe you want this distance to be one right so that that is what Chevy Chef distance is um then you have another distance Norm which is kind of the has a rhombus shape like this and that's called taxicab distance which is kind of uh going the other direction where maybe you want this distance from here to here maybe you want that to be a length of two so that's kind of it's called taxicab because if you imagine a bunch of buildings then this would be the path you would think um yeah so that's you can use different distance Norms but the the perfect circle is usually called euclidean distance can we get a spell here in chat um Championship distance I think it's spelled like that or wait actually I think the second C is incorrect there we go if you look up distance Norms on Wikipedia um then you'll you'll find it if you want to jump down this Rabbit Hole uh you can also interpolate between them smoothly if you want to which is kind of neat um if you want to have weird vector normalization okay how are we doing on time uh okay five minute break we're on our break now five minute break hell yeah I got the spelling right proves I'm I'm I'm a good teacher right it's all about memorization it's not about anything else okay five minute break for resuming in well a little bit in the past um 11. is there a difference between distance and length uh yes the the length is the length of one vector the distance requires two vectors um so distance is from one vector to another uh while length is the length of a single Vector so it's kind of just a difference of the number of inputs right the length of a vector is usually I'm going to change this now to make this less confusing so if you want to get the length of play Vector a because I kind of should have probably written this in Vector notation actually we're going to do the opposite um we're still on break by the way so if you want to go get coffee or tea or whatever then this I'm just I'm just keeping on teaching during the break because Bradley that's that's how I do okay so so really what we're doing here we're taking the a DOT X or the X component of a which you would usually do a DOT X and then we're doing um oh geez this is a little messy I apologize and then a DOT y there we go this is this is how we would write it in code because you usually get the components using dot using the dot notation like this I hate the tablet interactions with where is this um goodness the kid's outside are screaming so much I don't understand why it's just incessant screaming why there we go now we have the sort of sort of proper proper way of writing this for code um uh when I tried the square root of oh yeah so so like uh Joe bins is saying um yeah so so when you do the square root of a number um then negative numbers kind of automatically turn positive as well um specifically when squaring it if you're cubing it then it's going to keep the sign yes that's the that's the issue automatic I presume so if you take five squared is 25 negative 5 squared is negative 25. and negative 5 squared is 25 because it's a negative 5 times negative 5 in that case I said the signs cancel out [Music] hmm thank you did that make sense Adam apologies for my bad fines it's a very very ugly numbers I'm I'm not good at writing and writing at all foreign Break by the way I'm just or maybe we should end the break very soon um wait I lost the channel there we go okay there are so many future games discards bye we have cats we're where's my button there he is it's Thor hello hello there he's thinking okay did the did the thing about the square root or the the squaring makes sense but negative numbers he's just sitting there very pristinely what would the length of that Vector from A to B B um we can do that if you want thoroughly unimpressed cat yeah um he's not impressed by y'all or maybe he's not impressed by me it's it's either of the two oh he got curious about something blink um sorry I have a bit of a weird streaming setup right now maybe I'll keep the camera on Thor um okay so what would it be that was the question um so uh we would need to get the vector between these two right so if we're doing um let's see we're doing a minus B ow ow [Music] e body okay so if we're getting the if we want to get the difference between a and b we need to figure out the value of that Vector first [Music] um so let's figure that out if we have let's see so the X component of a is three x component of b is two so we're doing uh three um three minus negative two so that's the same as 3 plus 2. so we're gonna get five for our X components um and then for the Y component uh let's see so that is is y component is 1 and then B has a y component of um or a height sorry I should I should draw it in green uh B is two so we're doing one minus 2 so that's negative one um so so this is a minus B and then we want to get the length of this um so again that would be the square root of um before I left so so we would do five um squared Plus negative one squared okay and so we just need to calculate that and so so what would that be that's the square root of 25 I forgot how to draw two 25 plus so negative 1 squared is one um there we go so it's a square root of 26. and then that's that's that's the length of that Vector I don't know what the square root of 26 is so we're firing up the calculator so did 26 uh I've never used this before is it that one there we go that's our answer [Music] okay did that make sense okay cool um all right uh getting getting a little messy with all these scribbles okay [Music] um cool okay so we only have an hour left um I also need to make sure we're no longer on the break react please there we go react if you're present because we're no longer on break important stuff coming so now we're going to talk about stuff that's going to be Central to your your first assignment um okay cool you're all here so um let's see which layers this on that one I'm gonna scoot this out of the way I'm going to copy these very useful little coordinate system okay um so we've talked about the we've talked about adding vectors we've talked about getting the length of vectors we talked about getting the distance between two vectors and how to normalize vectors um so we have adding subtracting and then also multiplying by a scalar so ow ow Thor Thor okay um and so if you out this boy go eat okay so if you have a vector then uh sorry I got so sidetracked by Thor poking me um so if you have a vector v and you want to add it to another Vector Let's Do A and B again so adding vectors is pretty straightforward we have a vector of a vector B and then really all we're doing is we're taking the X and Y components and adding them separately and the same thing goes for a subtraction like vector subtraction works very similarly you just do a minus B and then you just do it per component um the same thing goes for scalar multiplication and division so if you have a author um and so if you have Jesus Christ okay I'm going to give you the Thor cam so you can see what's going on how hey buddy I'm trying to teach math here okay if if you have a vector um a and then you multiply it by some scalar so not a vector um owl so if you multiply it by a scalar um let's call it s um so again scalar is just a number it's not a vector then we also do it component noise so a times s in this case um is going to be the the X component of a times s and then you would have the Y component times s and then you just you just do it per component as well um and the same thing goes for division you can do the same with division but weird things start to happen when we start asking the question of what is a multiplied by B um and so the symbol we're using here matters a lot so usually in math you don't you omit the symbol if it's multiplication so so a b should be a multiplied by B uh but this is an operation that has many answers uh there are many different ways of multiplying vectors I'm like gesturing with my hands even though the camera is not even on me um so multiplying vectors is something that is usually not defined as a single straight up multiplication um I'm not going to get into too much about why that is because it gets complicated but so generally when we multiply vectors we have different a few different ways of doing it and so this is where you might have heard of the dot product and you might have also heard of the cross products so these are kind of the two most common ways of multiplying vectors um so let's talk about the dot products um so the dot products usually write with a DOT which kind of kind of makes sense it's in the name um this cat ow um so the dot products between two two vectors we have a um and then a DOT B so that is the the dot product um so let's let's talk about the dot products um any more space okay I should write it out somehow it's really really hard to focus when you have a cat poking poking your arm consistently okay the dot products this is a very special operation and it's very very important um so what is the dot product the the dot product is used in many different cases and depending on what type of vectors you use it with it basically tells you different information about those vectors um and so the dot product is also known as the scalar product it is also known as the symmetric product sometimes also known as the interior product it has many names but generally people are going to be calling it The Dot products um okay so what what does the dot product do um well first we can we can write it out algebraically um so the way you calculate the dot product um so we got a DOT B equals okay so the dot products to calculate this you do a um dot X so the X component of a and then you multiply that by the X component of b and then you add the y component of a multiplied by the Y component of b um so this is how the dot product is defined for for 2D vectors it's the the pattern is the same for any number of dimensions uh but this is the the definition of the dot product um and so you basically just take the X components multiply them together take the Y components multiply those together and add them all up um and so there are a few things you might notice just looking at this uh for one the dot product between two vectors is not a vector in and of itself because again this this is just a number like the X components multiplied by each other is a number the Y components multiplied by each other is also just a number so it's just a number plus a number right so this might turn out to be like you know five plus eight um and then the dot product is just a number and this is why it's often called a scalar product because you're taking two vectors but the result is a scalar not a vector and again scalar is just a different name for numbers right um okay so this is how how you write the the dark dot product algebraically but then the question remains like what is the point of this what is what is what is this number represent um and so that is kind of the the most important part of the dot product like what's it useful for [Music] um so there are two two primary use cases and a third one that's a little bit more weird um so the first one is if the if a is normalized um so a way to write normalized vectors or unit vectors is to put a little hat on top of it like this so this means that the length of a is one so whatever a is we normalize it and set the length to one um if we do the dot product between a normalized vector and a non-normalized vector we get a special case of the dot product called scalar projection um okay so scalar projection is a special case of the dot product where one of the vectors is normalized so what does that mean well what is what is scalar projection well let's draw our vectors so again normalized vectors have to live on the unit circle so I'm attempting to draw a circle one day there we go close enough right um so a normalized vector that's going to be our a so we would draw some some Vector here so this is a but normalized so we're going to do a hat okay so far so good right and then we need our Vector B and B can be any Vector we can draw it wherever we want so let's let's draw it uh over here so maybe this is our Vector B so the scalar projection between these two vectors is a single number and that number represents let's see just just extending the direction of this one just for visualization purposes um that number represents how far along a is B and so what it's really representing um so if you imagine projecting B onto this line so we're taking this coordinate and kind of flattening it against the line of a then what the scalar projection gives us is the signed distance of B along this line right here so it gives us that distance so again this is a a hat uh B it's a DOT product between those two and so that's what the dot product gives us so it gives us a single number representing where is b along this this direction right um and so in this case the number we can sort of measure the distance and kind of eyeball it and we can see that in this case it's probably this this length is probably a little bit more than three right if we rotate this down we can probably imagine it's like I don't know three point something right um this is one of the situations we don't want abs the distance since we need it signed uh it depends on the use case for your scalar projection you can use apps if you want to it depends on what you're doing with it right um but like you say we we can do this using negative numbers too so instead of using um instead of using B here we can use a different value it's a different value for B um so if we instead use I don't know how to get thickness right okay so if we instead use this Vector for instance so let's say this is our new value of B um then again we can extend the direction of this one but we're extending it to the to Infinity both forwards and backwards um so that's a and then what the scalar projection does it's kind of in the name projection we're taking the the value or the the vector B and project again onto the infinite line that the direction a um represents so again it's a 90 degree angle there and then the result of the dot product is going to be the signed distance along this short line here so this is going to be um a-hat Dot B and in this case it's going to be a negative number because now it's on the back side of a it's no longer in front of a it's now behind a um and so scalar projection is used a lot when you want to figure out the relationship between two vectors um and so in this case if you want to know is an object in front of or behind some other objects you can use the dot product directly maybe a is the again we can use the direction of a car that's driving or something so a car is driving along in that direction um and then you want to figure out is something in front of or behind you uh then maybe it's some some object or whatever if this the dot product between the direction of the car and the vector to the object itself if it's negative it's behind the car if it's positive it's in front of the car and so so this is something that the dot product is used for all the time when you want to know is something in front of something or behind something um so you're finding the shortest possible distance between the B point and the a vector um well it's the shortest distance of B projected onto the infinite line of a um and that distance can be negative so it's assigned a distance um so it's either negative if it's behind a or it's positive if it's in front of a okay did that make sense lots of people typing that's exactly your use case in your game project well there you go you can just do do some scalar projection so it's essentially figuring out if something is in front or behind something else uh yes and not only that it also gives you how far in front of or how far behind it is um so again we can use our car example where the direction of a car and then maybe we have maybe we have a different car maybe it's a racing game and you want to know how far in front of the red car is this car uh then we take the vector from your car to this car and then we project it onto the direction that you're moving and then what we end up getting is how far ahead that other car is and that's the dot product between um the a normalized um and B and again if this is um if this value is a negative it's behind if it's positive it's in front in fact if if the if it's not normalized uh that rule still holds um if it's not normalized then if it's positive it's in front if it's zero it's exactly perpendicular and if it's negative it's behind it but you won't get actual distance values unless at least one of them is normalized um so the normalization is a required if you care about the specific distance here but if you if you omit the normalization then you can no longer rely on that distance but you can still check the sign if it's positive or negative or zero um so so the dot products without normalizing one of them can still be used for that can you write out the value we get um it's a little bit complicated because we have a normalized vector and so it's going to be a decimal point thing um and so it's going to be a little bit messy but we can do it in code if you want to if that helps we can open unity and try it out um could it be used for example for a stealth mechanic where an AI only did this as a player if the dot product is positive uh yeah you can do that the dot product in general is also used to get the angle between two vectors but we're going to get into that when we get into trigonometry uh so would we use the position of the car plus its forward Vector um you would use the forward Vector of the car that's a and then you would use the vector from your car to the other car right which would be well your um it would be I forget the direction other cards other car position minus your car position would give you this blue Vector B right uh did you apply a tan two uh we're gonna get into that during trigonometry but not not yet uh we don't have time for trigonometry today I wanted to but we have to cut a shirt because you have a different class uh actually no trigonometry is far was supposed to be for next day uh not not today um okay did that make sense in terms of what scalar projection is and again it's called scalar projection because it just gives you a number it doesn't give you a vector it just gives you a signed distance along some other vector okay um I hate how we're short on time I wanted to go through more than this um I also need to sneeze excuse me if I'm just a correctly scalar gives you two objects of distance and relative position to each other uh yes it's the projected distance along a given direction right so yeah it's the the signed distance along this so you can imagine taking the the vector B flattening it against the direction of the other one and then getting the the signed length of that uh if it's a normalized specter will the answer always be between negative one and one uh yes if both vectors are normalized um then you get then the the it's always between negative one and one um and so um drawing a quick quick Circle so both of them are normalized it means both of them have a length of one so in that case the um the dot product between these two um kind of represents how similar these two vectors are um so if you imagine the um these vectors pointing in the same direction the dot product would have a value of one um if the dot product or if if the other one is pointing perpendicular to each other uh you would have a value of zero um if it's pointing exactly opposite then it would have a value of negative one um and then I guess we should go full circle because why not um so this would be zero and if they're pointing exactly in the same direction um it would be one um and so if both of them are normalized you can kind of use this as a substitute to get the angle between two vectors the the scalar the dot product doesn't exactly represent the angle um the you still have to do another step in between you're going to need the arc cosine which we're going to talk about later um but if you do the arc cosine of a DOT P then you get the angle between the two vectors if both of them are normalized so so again we should put some hats on this but we haven't talked about trigonometry yet so this is spoilers you didn't see this this is hidden so imagine this is nothing okay um I've used a DOT product before to figure out where an attack was coming from relative to a shield and if a shield could block it uh yes that is a common use case um a another use case that is pretty similar to the one you just mentioned um I was implementing sound for a game um so let's say you have some surface um and let's say you have an object that is uh falling down maybe it's a it's a ball and it's hitting the ground and then you want to play an audio clip um so you have some audio source and but but then the question is how how loud should this be um well we have some intuition that like if this is moving very quickly it should be louder right but we maybe we want to make a distinction between this one hitting almost straight on versus a ball that is hitting here right clearly this one should be louder than this one because this one is it's kind of a shallow angle right it's not as hard of an impact whereas if this ball is sitting here or maybe we can do it even straight on like this uh then obviously this should be louder of an impact than this or maybe we even want to use different sounds depending on the the shallowness of the angle right and this is a use case for the dot products because really what we want is have some variance depending on the angle and magnitude that it hits something um so what we're really looking for here is that we have the velocity of the object itself right let's call it V and then we have the direction of the surface you can sort of Imagine This is called a normal Vector that's a vector pointing directly out from the surface so so these would be normal vectors and normal vectors are almost always normalized as well so these are normals and so if you then do the dot product between the normal and the velocity then you end up projecting it and you you're getting this assigned distance here now it's going to be negative um but if you negate it then you get basically a value that can pretty accurately represent how loud that sound should be because as soon as you have a shallow angle like you can imagine a vector pointing like this then the the magnitude is going to be much much smaller right you can see that that this value is much much bigger this is bigger this is smaller um and so so that was like one use case for the dot product of like yeah the velocity of some some objects and you have the normal of the surface and the dot product between those two can be used to determine how loud uh that sound should be um does vector3. project on Plain use dot products then uh almost certainly yes I haven't looked into their source code but I'd be surprised if they didn't um so this is an actual use case I've had in in my game um there are many many many many different use cases for the dot products so if you want I can just have a grand bag of use cases um okay um does Dark Souls use the dot product to check for backstabs probably um again it's all about the relationship between directions that is what the the dot product is used for um you can use angles as well if you want but it's usually a bit more costly to compute and so you can quite often get away with not calculating the angle but for one-off things like that if you're doing a backstab thing then checking the angle is not going to be um it's not going to be that expensive it's not like you're running it every frame anyway so can call it a freeze frame if it's very very um taxing on your computer um okay let's see we have 20 minutes left okay um oh it's a little little bit tight um but I think I think we have time um okay maybe we should jump into Unity um and I can show you a little bit how I usually work with unity to do math things like this um and then I will give you assignments how does that sound um how how angry will y'all be if I go a little bit above or Beyond uh or like overlapping lunch a little bit is that okay oh I haven't seen this interface before I don't know 3D I think I know the folder doesn't exist I wanted you to create it jeez e I'd rather the lecture end at a good point than End early okay I just don't know if you have any like um if you have any things you need to head off to oh God what is this layout wait why did it start Unity 2020 gross why did it pick that yes I want to upgrade I know okay I'll try not to override lunch too much okay this layout is trash garbage so I'm just gonna Shuffle this around um okay beautiful um okay one thing I like to do in my Unity project when I'm doing like math things is I delete the light source and then I go to the where is it lighting Tab and then I delete the Sky Box and then we we go into 2D mode because that's a little bit more comfy and then we have a nice grid and then we delete the camera we don't need cameras there we go we don't need anything we just need an empty game object uh you've used Unity before right I don't need to cover how to use Unity I'm guessing uh I removed everything in the scene and in the lighting tab I removed the Sky Box there's a material assigned for the Skybox so I just deleted that okay so one place I really like um experimenting with math and testing things uh is in the Gizmo drawing in components so I'm just going to create a new script um I'm gonna give it a very descriptive name of my thing I trust this come on Ryder process a little faster Okay so um I actually forgot what example we were gonna do uh I guess we can just talk about some of the things we we've already covered when it comes to distances and whatnot just to implement it in practice um so I usually like doing stuff like this in a function called on drug gizmos on draw gizmos will be called in the editor so you don't have to press play it will just work um and this will draw in the scene View just kind of nice um so in here you have a lot of functions in unity in gizmos dot draw whatever so maybe you want to draw a line from two points or maybe you want to draw a cube or maybe you want to draw a sphere and so forth um so maybe we can do with draw a sphere a transform Dot um position with a radius of one so this is not Unity this is Photoshop so now you can see we have a very low poly sphere that is being drawn at the position of this game object and this is super useful for doing debugging stuff and especially for testing your code to see if it works um and so so maybe we can do an example of the dot products so let's let's create two more objects um we're creating a and B um let's give it some labels it's visible right you can see the yeah okay I think that should be visible um I'm just not sure about resolution and stuff um okay so now we have two game objects A and B and then we want to do some math with them so we need a reference to them in our Scripts so they are transforms did we go through cross product tomorrow uh yes yeah a lot of these things we've talked about translate to 3D as well but the cross product is unique to 3D um there's not really a cross product in 2D they're kind of is but that's goes beyond the scope of what we're going to talk about um okay so we have 202 transforms A and B I'm just going to drag the references uh we're gonna stop drawing the sphere and then we have our two two vectors we have a coordinate of a which is going to be a DOT uh position let me do the same thing for B so now we're kind of in our in our usual math situation um so maybe we can draw those vectors so we draw a line from uh if we want to draw a vector we want to draw it from zero so I'm just going to do a defaults to a and defaults to B I don't think there's a color parameter right okay I think cyan is going to be more visible um okay so this should draw two lines just from zero to um A and B hopefully they're visible they might be a little thin on stream after compression and everything okay hopefully that's visible um and so now this allows us to kind of experiment with our math and kind of test it in a very isolated case sometimes when you're writing like math heavy functions it's very very very useful to not test them in the context of your game because usually there's a lot of like other variables that interfere uh with trying to figure out how things work and so it can be very useful to like work with these things in isolation um okay so so what are the things we've been talking about so let's try normalizing um so maybe we want to normalize a like what would that look like um so uh so let's call this a normalized and then we want to do we want to take the vector a and then divide by the length of a right now there are many like built-in functions to do these things like you don't always have to write out the math yourself um so what we talked about earlier uh doing it like manually uh then we would do the Pythagorean theorem like straight up so the square root of um a DOT x times a DOT X plus um a DOT y times a DOT y uh so we're just squaring here right uh or this is the length sorry um so that's a length of a right uh now we can also just use the built-in functions here right we can calculate the length uh using just a DOT magnitude that basically does the same thing so you can use whichever one you want um but this one is going to be slightly faster if you're doing very performance sensitive code um it can be useful to write things out like this because magnitude has like an extra overhead when calling the property but generally in most cases you would just call magnitude because it's way more readable right uh but it's good to keep in mind like what the underlying math is sometimes um okay so this gives us the length of a and then if we want to normalize a we can do a divided by the length of a um or we can just do a DOT normalized so this will also give you the normalized version of a um so this is kind of the manual version um well either of these two or the quick and easy version generally again generally you would use the quick and easy version but now you know how these work like under the hood right um okay and then we can draw this one so let's let's draw um let's draw a sphere at the tip of the normal lace Vector uh we're gonna do something like that and we want to color it by a as well um can we just create a magnitude extension method returning the more performant one uh no because then you have the overhead again the overhead is is in the fact that you're calling a method uh and so it's it's going to be about the same um um okay so now we should be drawing the normalized version of a um and so here we're drawing a DOT at the normalized version of a and you can see that no matter what length we set a to um the normalized version always has a length of one and you can see that it's it's sticking to the unit circle right hmm um one point of optimization ask how often it needs to be called and called it just as often as that yeah yeah the um again it's mostly if you're doing like very performance sensitive code if you're iterating through like 500 things and you want to get the distance or the length of 500 Vector vectors then then maybe it's it's a good idea to write the math out explicitly and not call a bunch of methods um but it really depends on use cases okay so now we have the the normalized version of a um can make it a little bit tinier because it's a very large blob [Music] um and then for the scalar product of normalized dot b was it zero when B was perpendicular to A and negative one when it was behind yes a negative one if it's exactly behind if both of them are normalized the dot product is always negative if it's behind it's always positive if it's in front of It's Always zero if it's exactly perpendicular um but both of the vectors have to be normalized for it to be guaranteed one and negative one when they're either pointing in the same direction or opposite um okay uh so let's let's do the let's do the dot product um so um I don't know if I should keep these if you want the code afterwards I don't know what you I don't know what you prefer um all right so we have a normalized vector and a non-normalized vector so now we can we can look at the dot products um so let's do scalar projection between these two um so if we then take the dot product so that's in vector2 dot dot that's the dot product um then you pass the vectors in there so we have the normalized a uh and then you have B and this gives us the scalar projection now this is just a number um I don't really know how we want to display it we could just show it in the inspector um or something um actually we should probably just name that after the variable itself okay so now we move these around it might be very hard to read this number but you can probably at least see that it's changing right um so it's positive on this side um so in this case it's it's 1.5 when it's pointing along the same direction as B um and then it's negative 1.5 pointing in the other direction and if it's perpendicular it's going to get closer and closer to zero and if it's exactly perpendicular it's exactly zero but because floating Point coordinates work the way they do you don't always get exactly zero um why is the negative 1.5 and not negative 1 and that's because B is not normalized so we're doing the dot product between the normalized A and the non-normalized B um so the value is going to depend on the length of B right now and so that's why it's going to differ like that um yeah so when one of the numbers is not normalized we get the dot product with a multiplier yep exactly so so the the geometric interpretation of projecting onto the line only works if one of them is normalized or at least one of them is normalized if none of them are normalized um it's kind of like projecting and then scaling by their lengths um which is a little bit different um and so we need to be careful about how you use it so in order for it to be scalar projection at least one of them has to be normalized and so that that's what we're doing right now um then there's a another um there's another way we can use the dot product um and so the the name scalar projection might you know hint that perhaps there's a vector protection and and damn there is imagine that so we're gonna we're gonna do Vector projection as well okay Vector projection is slightly different there's there's one important difference so instead of just doing the normalized a dot b we're also going to multiply that by normalized and so now with Vector projection the result is no longer a scalar this time it's a vector and this Vector gives you the point at which it was projected to so now it's not just a distance anymore now it's a point and so if we use a different Vector that makes it a little bit more readable so if this is B and then we project it onto here this point right here the vector from from zero to that point is the vector projection um yeah and so that would be this right here that point is um the dot product between a normalized gives us the uh signed distance along it and then if we multiply this normalized vector by that signed distance which is what we're doing here we get that Vector pointing um exactly at the point it was projected at and so that's Vector projection and so it's very similar you just multiply it by the vector that's normalized and then you get the point here um and so that's Vector projection and this is also super useful if you want to actually get the coordinates where this projection would happen to or happen at so if you want to project something to a plane and you want to get that location or put something there then then you can use Vector protection to get that coordinates uh coordinate out of it um and so let's Implement that um Vector projection um and all we need to do here is we're taking our um let's call this the projected points uh actually we should probably follow the same convention Vector protection is going to be the a normalized multiplied by the scalar projection and then we should probably draw it um there we go foreign that's not Unity okay so now if you move B you can see that we have the projection onto the line of a and so so now there we go they project this onto this no matter what the orientation is we get the perpendicular projection onto the the infinite line that a represents what's a use case for this um let's see um one very good use case is going to be your assignment so I don't want to spoil that um I need to think about something else that's like a really important use case too um well any any time you want to flatten something against something else you know um it can be used to or no that's a bad example actually can't think of any any good examples right off the bat um find the distance between player and ground yeah the problem with that is that you're gonna um the problem with that is that that's distance not the vector projection um and that usually you would just use the components right of the factory um go up slopes um yeah you could use that um I mean it's a type of snapping right like if you're if you're close to yeah like a slope in a 2d game um and you want to make sure that you're actually sticking to the slope maybe you're going to be slightly off and you want to snap it to to hit the actual slope um place a Target marker for where a bomb should land um that could work too yeah assuming the you can approximate your terrain using just a line um the um actually we had the the racing game right like you you could use the the scalar projection to figure out how far ahead a car is um and you if you want to draw some sort of marker where that is maybe you want to draw a little dot for like oh this car is about this far ahead of you or whatever then you can use the vector projection to get this point right um yeah a lot of any time you want to flatten something against a line right okay uh I'm guessing we don't have a whole lot of time left no we do not okay time for assignments um okay I'm gonna try to try to be quick um [Music] okay I think I think the same assignments from last time is good I think we actually caught up with what I wanted to have as assignments okay um so let's I'm gonna give you two assignments uh and a third one that's a special assignment um okay all right I don't know if I should have a separate document for the assignments but all right so the first assignments let's do assignment one there we go what a number let's color code them um or no actually we're going to do three assignments and then a special fourth one or no wait you don't have a whole lot of time to work on this I guess Stockholm deaths um I don't want you to like stay up super late because you have lectures tomorrow um all right the first assignment is to create a radial trigger so when I mean create I mean code implemented in unity uh to create a trigger where maybe you have some let's say it's a game where you have an explosive Barrel this is this is a dangerous danger Barrel um you don't want to go too close to this one it's that's a flame um so I want you to create a radial trigger where there's a radius around an object where you need to detect if something is inside or outside so maybe you have a player character and you need to detect if they're on the inside of the explosion radius of this Barrel or not so just doing a simple detection are we inside or outside um that is the the first assignment okay guessing that's pretty straightforward and clear what that means um okay and then the second assignment um the second assignment is to create a scene okay bouncing laser oh and for the radial trigger you're not allowed to use colliders and this is specifically a math exercise so I want you to this distance measurements to figure out if you're inside or outside right um I want you to make a bouncing laser um and so if you you can create some sort of terrain in unity um I don't really care how you created as long as you have some sort of colliders in your scene that is terrain uh you can just create a bunch of like Unity Primitives or whatever whatever kind of shape you want to make for your I'm just imagine like a worm scheme or something um whatever you want to use you can just slap in a bunch of like cubes and spheres or whatever but I want you to create a bouncing laser where you can use unity's raycasts to do this where you start from some point and then your raycast and then I want you to do the math to create bounces so if you recast against here I want you to make that bounce and then I want you to code it so that it bounces um well however many times you want it would be nice if it's configurable so you can set how many times it should bounce and so this this is the bouncing laser assignments um for this one you are not allowed to use unity's reflect function this is an exercise in figuring out how to write your own reflect function so I want you to figure out how to do this reflection using only what we've talked about today so you're not allowed to use unity's reflect function how do we calculate the bounds that is what the assignment is so I'm not going to tell you the answer to that so I want you to try to figure that out on your own so try to not give answers to everyone because they exercise to figure it out but again I have given you all of the tools you need to figure that out so everything I've talked about in this course uh so far you have those tools um and so so you're going to figure out how to do a bouncing laser um you're not allowed to use vector3.reflect um because that basically just solves the problem for you and so the exercises to to build some intuition about using the tools we talked about um okay I feel like we didn't talk much about the normals um Ray casting gives you the normal straight up um so you can use unity's raycast to get the normal um and so that's that's where you're gonna need for this um are we supposed to do it in 2D or 3D um whichever one you want um the solution should look the same regardless of which one you're using um okay I want to give you another one but it feels mean to do it because you don't have a whole lot of time to work on this um was this to be turned in um I I'm not gonna double check to see if you've sold it or not um again it's just to make you I want to give you the opportunity to exercise this and to build intuitions about how this works um and so I'm not going to check your assignments because I honestly don't have time because there's a lot of students and so yeah um we could do feedback sessions if you want to but it's probably not going to be during the lectures it's probably going to be after um and um the second week we could also do more interactive stuff like that if you want because again the second week I'm going to keep a little bit open so we can decide together what we want to do the um second week um okay I think I think okay so I think I think the the third one is going to be the bonus assignments I wanted you to do this as a as a non-bonus assignment but I feel like we might be a little short on time um and so for the last assignment the bonus assignment um okay um it's basically going to be vector transformation without using the built-in transformation functions again it's a math exercise um so from Vector transformation um with DOT product it doesn't matter which Vector is passed first no it doesn't you can do it in any order the result is the same it matters only in cross product right [Music] um it matters in other products too but yes it does matter in the cross product the cross product is anti-commutative meaning that a times B is equal to negative B times a um so that's the cross product okay so this is the the bonus assignments and there are two parts to this so let's say you have a coordinate but not only do you have a coordinate but you also have a space here like a local space and you can sort of imagine this being the um the directions of a transform in unity so this is transform.write and then we have transform dot up as well so this is kind of like a game object right um and so what I want you to do um using these vectors you can use transform.app and transform.write for this assignment but I want you to write a um local to World function locat in other words you should be able to give a local coordinate as in a coordinate that is a relative to this space and so maybe that coordinate is going to be here and in local space coordinates this would be represented using um in this case like 2 on the x-axis and one on the y-axis I want you to write a function to transform from local space to World space so where is this in a world space given a local space coordinate and so the world space position of this one would be different in World space which is this coordinate system here it's going to be like 2 it's a two points I don't know six on the x-axis and on the y-axis it's actually also 2.6 ish 2.5 and so I want you to write a function that converts from a local space coordinate to a world space coordinate um you're not allowed to use matrix multiplication for this because that again kind of solves your problem for you we're going to get into that during our next lecture so in this case I again I want you to only use the tools that we've talked about during this class you're not allowed to use the built-in transformation functions you are allowed to use transform.write and transform.up if you want to um and so that's that's local to Worlds um okay and then finally we have the special the special um bonus bonus thing uh I don't understand like a child coordinate yes so this is like the the coordinate of a child object of the one on the left that that is a local space coordinate right but I want you to write a function that can transform from local space to World space without using unity's transformation functions so effectively I want you to write your own transformation function that doesn't make use of those helper functions and you can do that using only the tools we've talked about today um and so again it's a math exercise don't take shortcuts because that's that's not going to make you learn right all right and then three B this is the this is the special special edition we're putting a star on that I don't know with scaling too ignore scaling don't take scaling into account um okay so 3B this is going to be world to local so this is the opposite given a world space coordinate so maybe we have a coordinate over here or here let's say so this is going to be a coordinate of x axis as one y axis is 2. I want you to convert a world space coordinate into a local space coordinate so local space this Vector would be different right it's a vector like this um and so local space it would be I don't know be like a negative 0.5 and on the y-axis it would be like two and there you go and this is the bonus one and what the what the bonus one means is that if you solve this one if you solve 3B and 3A um I will put on cat ears for the next lecture I have them somewhere here where are they so if you solve that if any one of you solves it then then you will you'll be doing the the classic read service by having me wear a cat ears doing the next lecture so so there you go that's the that's the advanced assignments um all right I think we're we're running over time uh I'm sorry if we're going a little bit too far um I will send you this picture and I will also send you the code um yeah are there any questions how long do we have to do this uh we only have until tomorrow um because we're doing a lecture tomorrow so um yeah and I know that some of you have other lectures during this um and so and so some of you might not have that much time but I hope you can find some time for it and I hope your retrospective is not going to take too long um yeah but I believe that is it for today so I will send you can I just send this straight up I think so uh there are no more electricity uh so there you go that is the my document and then the script um just signing some instructions I guess ah Okay cool so this is the script oops so we do not have a lecture on Thursday I will give you assignments to work on whenever we don't have lectures so you're always gonna have something to do um so there you go that's the code um I hope that I think that's enough right [Music] um okay yeah sorry for overriding your lunch quite a bit um but I really wanted to get to this point um so that we can you can do the the assignments that I had planned um again do them in unity uh try not to take too many shortcuts try not to um just get the answer because a lot of these things have very simple answers uh but getting there is what I want you to go through I want you to go through the process of solving the problem of figuring out what what do you have and what do you need to get to the result that you want again it's a math exercise so if you look things up on the Internet they're just going to give you the answer and it's going to be too simple again I want you to do the math and try to figure it out on your own um yeah okay um I hope that wasn't too much and didn't override too far into your lunch I will let you go all of you people have future games um I will stick around for a little bit longer for those of you who are on YouTube and I want to abandon you all completely um yeah but as for all of you at future games uh I'm letting you go I you're no longer stuck in in my math class uh but but thank you for for for sticking around and not flooding the chat too much with memes um okay I hope this was useful uh we will go through the assignments uh tomorrow um and so so we're going to spoil them immediately so I recommend working on these today um and yeah that's that's it thanks future name students it's kind of weird to teach and not see all of y'all but um okay I'm gonna stick around for a little bit longer but the official future games section is is is done because you all need to have lunch um but now in case people on YouTube have questions then then feel free to shoot me questions and that now that I'm paying attention to you [Music] um next lecture is 9am CEST uh yes tomorrow I will put up a YouTube plan to stream thing it's going to be there so so you're going to find it on my channel oh don't forget to like comment and subscribe Etc so so you should you should do that I have a lot of math videos on my channel um also stuff about shaders and tools programming so if you're into that kind of stuff then then you should you should check out my channel but I guess you're already on my channel [Music] um I also have a Discord server if you want to want to hang out in my community um then then you can join join there there you go that's a link I don't even know if it's clickable do I need to include the https okay there you go if you want to join my Discord you're welcome to join we have a lot of game developers there people who are interested in the shaders or math and so forth uh yes uh this will be this will stay on YouTube don't worry about it um a lot of people have been asking about that but yes it will stay on YouTube um okay uh anyway do you have any questions YouTube folks small type of Photoshop if you hold shift it'll draw a straight line uh no because I'm using a tablet and the pen pressure makes that not work uh the problem is that when I press down the pen I get low pressure and so it's going to draw an extremely faint line it works if we're using a mouse but for a pen it doesn't work because pen pressure is a thing right and so when I hold shift yes it will draw a straight line but it's going to be basically invisible so I can't use that um I've gotten this recommendation a lot I've been wanting to pin a message with the FAQ but apparently that's not a thing mods can do uh wait is it possible to pin um like an idea that or oh yeah there's been super chats I think how do I read the super chats uh uh uh [Music] pretty sure you can configure brush to always be hard but I don't want to do that I want it to have pressure in general but not when drawing lines and switching between types of brushes is annoying wait how do I read super chats why is this hard I feel like there has to be a way to just see all of the super chats now I feel bad because I was expecting this to be possible oh no no oh geez so I need to scroll the entire chat super chats are broken on YouTube I don't think they're broken it's just that they're temporary and I wanted to I wanted to respond to those I'm confused okay well um can you use the dot product to see if it's to the left or right somehow um kind of yes um if you rotate it 90 degrees that's what you're checking you can also use something this gets complicated um but what you're really looking for is the wedge products sometimes called the perpendicular dot product sometimes called the exterior product sometimes called the anti-symmetric product sometimes called the 2D cross products so yes you can use that also sometimes called the determinants and so that one is kind of the thing that is checking left and right instead of in front of and forward but um We're Not Gonna we we I haven't planned to talk about too much about that um this this time around uh we're gonna get into that as soon as we talk about trigonometry then we're going to mention it what's the benefit of using Square magnitude to magnitude and unity uh squared magnitude is faster but it is non-linear um and so it's it's you get the incorrect distance uh but if you're just checking if something is greater than or less than some threshold um then using the squared magnitude is faster because you're not doing the square root so um I remember one of the super chats who was love what you're doing keep it up oh thanks uh what do you call Vector multiplication in the Shader uh the default multiplication of vectors in a Shader is called the hadamard product um I don't know how to pronounce it it's probably some German or something but hadamard product is the component-wise multiplication of vectors which is rarely used you sometimes use it it's kind of like if you want to scale each component by some value so it's usually scale related but you use it a lot in shaders because in shaders colors and vectors and positions are all interchangeable um do you have to memorize all the trig functions no definitely not I mean it can make you slightly more efficient but I would just look it up I look it up almost every time hotwireless French adamert I don't know I don't know French but um something like that yes the video will stay up on my YouTube channel um thanks for your videos it basically taught me how to do my job heck yeah I'm glad oh run yet do you want to be a moderator or would you would you prefer not to I feel like I just want to moderate everyone who who I know everyone who I know and trust okay you're wrenched I don't know if a wrench is becoming a moderator or getting banned uh is there a textbook that corresponds with the course or textbook you can recommend um no the Pro I actually I have no clue about textbooks because I just I haven't learned the things that I've learned through textbooks and so a lot of that is just kind of outside of what I'm aware of I'm sure there are textbooks but I just don't I just don't know um I'm sorry it's a really shitty answer because it's annoying um but yeah most of what I've learned is from like having to implement things and then just Googling for how to solve it write a textbook I've consider doing that I actually started writing it I made a prototype page um here you go here's my prototype prototype page I wanted to make an online um online math book that was kind of like a Wikipedia but it's actually readable for people trying to learn um and so so I that page is my test test page um but I've considered making a bigger thing out of it but I just haven't gotten to it because I'm kind of wrapped up in doing my video projects right now uh my the sequel to the bezier video I've been working on it for about a year now and I'm so tired of it I really want to release it um I am um yeah the it's a video about splines it's the again the sequel to The bezier Curve video so I'm going to talk about talk about explains what's gay uh usually it's uh referring to same-sex attraction but it can be used to mean other things as well foreign [Music] okay cat has stopped protesting or is really quiet yeah where where are the where are my kittens oh there's salad I don't know if you can see you can kind of see his butt sticking out of the window and then there's another cat on top of the tree um actually how long have we been going for uh okay I don't want to hit the four hour mark because if I do that then um uh YouTube is not gonna put captions on this video because because of course because you know if a video is longer than four hours the you can't automate captions anymore it's just how the software works you know for some God forsaken reason so I want to keep this under four hours wait is there a solar eclipse oh wait when so like now we're soon um too cloudy yeah it's happening right now damn yeah mostly mostly see clowns Auto caption software probably 32-bit and forever needs just about one gigabyte of memory but then just do it twice in separate like things I can upload 500 videos that are three hours and 59 minutes and it's gonna do it just fine but if I upload one video that's four hours and 12 minutes it's not gonna do it and it's like why salmon foreign so this is salad those of you who haven't met salad you want anything in my lap s what's up what are you going behind my monitors buddy oh geez the cheese he's behind he's just up to stuff boy is he gonna nap there now in my engineering class I learned vector.cross product but I just know the calculation not the application okay look that's the big issue right like I feel like application should come first before you learn the thing what kind of tablet do you have um we come into us the pro I think medium how um okay anyway um anything else before I leave any other questions how many cats do you own uh we have three cats we have a salad we have toast and we have Thor we've been streaming for about three hours and 40 minutes uh well the course cover sign distance Fields [Music] um not really we're going to talk about that during the Shader course but not the math course um yeah the thing is like the we've already talked about signed distance and so the field part usually comes into play when you have like a fragment Shader or a texture that contains a field of signed distances right um yeah salad you're being a little rascal this this and this boy he flew for scooter he flipped with scooter will this be the same as your prior gaming classes um yes the first few lectures will be basically the same um but the second week depending on um depending on how like what we're going to talk about I might do more lectures on things I didn't talk about last time yeah and so there's and usually like I don't have a super tight script that I'm following for my classes and so they're always going to be slightly different For Better or For Worse um and it also depends on what the students want um which topics were you thinking of covering week two that just depends on what the students want to talk about if they want to talk about splines then I will do that if they want to talk about easing functions I can do that um if they want to talk about geometric Algebra I can do that too and so it just depends on depends on where things go over you little goober he no one and you want to go someplace else how far is the bezier video uh the bezier video was done like a little bit over a year ago but the spline video I am still working on it is almost done uh it's I I'm just I have a tiny bit left to work on um and uh Jazz Mickel is also working on the music for it so whenever both of us are done uh that's when it's gonna that's when we're gonna release it hey sanded Criminal you just knock down my tablet pen no no what lava geometric algebra class but I'm not sure it's super relevant for First Years super useful though oh yeah it's it's completely useless um but I'm thinking out I'm gonna go through all of the relevant bits during the first week and then the second week I'm gonna basically field whatever people want to talk about and then pick out the more useful things out of that so if someone if nobody has any suggestion except someone really wants to talk about geometric Algebra I can do that but it's unlikely um uh as nurbs mentioned in the upcoming video uh yes but I'm not going to get into them in detail they're mostly mentioned at the end I wanted to go into detail for nurbs for the video uh but I'm not gonna I didn't have time for it and so it's not going to be in the spline video but I might do it in the future I mentioned them I talk about how they work and I talk about B splines just not full-on nurbs until the very end salad that is my that's my pop filter don't eat my pop filter this is criminal activities hey especially hyped for the spline video since every time I Tried reading up on it myself I quickly discovered that every article contradicts each other yeah it's kind of annoying what's a by Arc and what's it used for um it's a type of spline that is using circular arcs exclusively um and that it's used for whenever you want to do just circular arcs and um and that and that's what it's used for like if you want to have a spline where um it's really important that you have a fast Arc Length parameterization then you would use it um otherwise I don't think there are that many use cases for by arcs uh generally you would use something else um um is there a way to Benchmark shaders um just read your GPU numbers and try it change your shaders do a b testing that's what I do if you ever made a video about quaternions I cover them a little bit during my math course um and I will during this one too um but I don't really talk about how they work internally I just talk about how to use them and how to think about rotation and unity how old are your cats uh this big boy is eight months um okay yeah he's technically a kitten um he acts like one but he kind of doesn't really look like what he's very large yeah he's like he's like five point something kilograms now I think salad what are you doing hey don't eat my monitors yes the stream will stay live after I end the Stream salad hey you're uber don't eat the monitors yeah no that's a wiggle illegal this boy he is he is a boy still hate nfts yeah they seem pointless I don't know why why I don't hate them as much as long as it's like it seems like proof of work crypto was absolutely trash garbage for society and the planet and proof of stake seems slightly better but it's still kind of pointless I don't see why why like it just seems like a complicated way to do transactions that you can already do um I feel like it's very much a um solution looking for a problem to solve um and I don't see the use case for them right now and then it's also dubious like how much of a solution it actually even is um salad stop eating cables yeah no I don't know how to deal with this boy I don't know no no it's still still Criminal illegal buoy hey goober scooter he try stable diffusion or other types of AI uh I am at the point where I absolutely hate AI uh for generating quote-unquote art uh and so no I have not I am I am I am fine with the shitty AI that generate funny memes like dolly or whatever but as soon as it starts encroaching upon art I am deeply uncomfortable with the implication to Art society as a whole uh and so I I am very much against the type of AI that is generating um quote-unquote art pieces especially if it's stolen art that was taken without people's consent um and so so yeah no I have not been playing with stable diffusion because I think it is morally reprehensible look at this Criminal look at this Criminal with your premium broken are you doing the audio chain of software your mic sounds great it's harder processing worth it Hardware processing is not really that worth it no I mostly did it because I like having Hardware it's fun but you don't think it could be a tool for artists to use instead of replace them yeah I mean it can be but I worry that it's going to go much further than that like as a tool if it's like oh we can use it to uh like remove jpeg artifacts great that's a nice use of AI I'm for that but as soon as it starts doing composition as soon as it starts doing like the entire color as soon as it starts creating an entire scene then no I don't think we should use AI for this because now we're taking the creativity away from the humans and then we're just leaving the like then we're just leaving the cleanup work for the humans and then who's really the robot like if we just use AI to generate the entire Concepts and then we just use humans to clean it up I think that is a deeply dystopian future I think art like the process of making art I think has value in and of itself and to reduce it to just a product to just a means to an end I think is insulting and I think it's just hard harmful for society I think art has more value than that right silent rape and so that's why I do not like this thing you being against such AI won't change a thing it will come also if you really reminds her on the material then there's no difference uh I hard disagree with what you say there is absolutely a difference um and the if to me it sort of sounds like okay if if you um there's a new technology on the horizon and it will murder every child um and then I'm like okay this technology sucks I think we should legislate against it I think we should not do this thing I think murdering every child is something very bad and then you're like but this technology will come that that's not an argument as for why we should let it happen right uh there are many things that people are working on that I think are bad that we shouldn't do and AI art falls into that category for me um yeah so that's how I that's how I see it miyosaki reaction yes I strongly believe this is an insult to life itself isn't that a false equivalency it's not an equivalency with an analogy but um you know you know yeah salad you're eating cables that's why I'm holding you here because you're being a little rascal being a rascal s okay anyway um he's off the plastic anyway your comparison isn't valid we can claim the creativity is only for humans only because we're the only one doing it once Aya does it we need to change our definitions I think this is a bad future I'm saying that prescriptively humans should be the ones to do art I don't think AI should do art and so it's just a moral prescription um and so you can disagree with that if you want but that's how I see it right now um okay anyway um I think it's like worrying that GitHub co-pilot is taking programmers jobs and ironically I'm also worried about that but a little bit lesser um because games the code in games is generally pretty complex uh but yeah and ironically I don't think I think it would be I think we would lose something if the craft of programming and the craft of creating visual art is just dropped and just left to computers I think we lose something something very important um and I don't think we should drop that like I like a lot of these AI conversations are really frustrating to me because like a lot of people seem to think that everything is just about the end result and that the process doesn't matter and I think that is just such a like misunderstanding of what what art even is like people don't make art just to get results people make art because they actually enjoy the process of creating it they enjoy learning that skill they enjoy doing that and and to just say well we should just turn this into an AI thing I disagree I don't think we should I think I think that is that is bad like there are so many other better uses of AI like I don't know we can we can use AI to uh what's the like protein folding thing we can use AI to figure out like molecular stuff and a shitload of stuff in science we can use it to like again like clean up jpeg artifacts or like do like tedious work that nobody can or wants to do that's what AI should be used for but as soon as it starts taking over composition and color and lighting and like everything that artists care about and wants to do then I think we have gone too far and I think that is bad um and so so right now I feel like it's I don't think it's something we should do especially not when it starts like stealing people's art and using that as their like basis for their models I think that is immoral and I don't think we should do it um and I think models should only be trained on like consensually given art um and right now the most popular ones are not uh anyway okay I shouldn't rant about this too much I'm gonna go insane I actually care a lot about this topic and I get really frustrated and so I shouldn't I shouldn't delve too deep into this this is actually in some cases throwing me into feeling really shitty for like the rest of the day um if I go too deep so I I'm uh anyway are there any other questions math I don't know if that's a question just because you put a question mark at the end calculus relevance to game development um if you're doing a lot of stuff that integrates over time like if you're writing a physics engine calculus is going to be really important it's going to be useful if you're doing a rendering sometimes if you're doing volumetric stuff uh that kind of stuff how do you press a shape like a five-point is star into a flat plane to make a 90 degree World imprint and unity I have no idea what that is asking do you have any advice for people who aren't strong in math skills wanting to learn math for game development yes my course on YouTube uh this one is not edited uh but the previous one on my channel is edited and a little bit tighter than just this live format uh oh they're older students tuning in that's really neat how to keep yourself from Forgetting 90 of the math you learning courses um mostly through using them in the work that I do [Music] um uh do you do anything outside of work to keep yours keep you so smart I don't know if I'm smart um I did not do any other mental exercise apart from doing the work that I do um but um no no I don't think I have anything like I I just try to do work and then through doing work I learned the things that I do and that's what I want to do and so that's true I do regularly get nerd sniped on discard unfortunately I help too many people on Discord like generally companies would have to pay me to have my like consulting services but the secret is that I actually give it up for free sometimes on Discord because the problem is just so interesting that I need to do it so yes the class is over we're doing post post class chatting right now um oh yeah we're closing up on the four hours uh uh check the description of this video if you want links to my stuff uh if you want you can support me on patreon I have a link there as well um I that I also try to insist I tell future games that I really want to do this publicly as well so that other people can take part and learn uh if you want to join my Discord I have a link there if you want to hop in um and there's a flying salad in the background but thank you all for tuning um and windows is currently covering the timer um okay thank you all for joining I have to end before four hours um and uh thank you thank you so much for for joining we're gonna do another class tomorrow and so feel free to tune in and I'm going to put up a a pre pre-rolled YouTube video on my channel if you wanna if you want to enable notifications for that if you don't want to miss it but thank you all so much for joining and and I will see you all tomorrow if you join otherwise I will not see you uh but thank you so much and I will I'll see you all next time
Info
Channel: Freya Holmér
Views: 602,927
Rating: undefined out of 5
Keywords: Acegikmo, Freya Holmér, Freya, Holmér, Twitch, Unity, Unity3d, math, vectors, dot product, scalars, numbers, mathematics
Id: fjOdtSu4Lm4
Channel Id: undefined
Length: 237min 35sec (14255 seconds)
Published: Tue Oct 25 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.