 A squared plus B squared equals C squared. Cool story, bro, but how's it relevant to me in my life? If you find yourself asking that question and you like making games, I might have an answer for you. Because in this tutorial, I'm gonna share with you an application of Pythagoras' theorem in real life using Scratch, coming your way in just a sec. Hey, what's up, crew? It's the Surfing Scratcher here, teacher-surfer programmer, and I help curious people just like you along on their learning journeys through video tutorials. In the last tutorial, I showed you how to get this rocket ship moving across the screen using X-Velocity and Y-Velocity. As always, I've got a starter project available for you down in the description, and there's also a card in the top right-hand corner right now where you can go check out that previous tutorial. You can get through this tutorial without watching the previous one, but if you've got no idea what I mean by X-Velocity and Y-Velocity, I strongly encourage you to watch it. This tutorial is gonna teach you two things. We're gonna create a variable called speed, and we're gonna be using these two existing variables to help us understand that, and we're gonna explore what this operator means, this square root operator. So to do that, we're gonna jump over to Sketchbook. Okay, here we are over in Sketchbook. I've got our little rocket ship here in the center. We've got the X going across and the Y going up and down, and over here, we're gonna be exploring Pythagoras' theorem. What if it actually came up in real life? We're gonna be using Pythagoras' theorem in our game, so games are technically not real life, but they occur in real life, so I'm claiming real life. We're gonna be using Pythagoras' theorem to understand speed, but firstly, the theorem. So we've got A squared plus B squared is equal to C squared. Can think of this as the square of one side plus the square of the other side equaling the square of the longest side at the right angle triangle. And here's our formula. A squared plus B squared is equal to C squared. Now we can just substitute some values in. So we could make A equal to three, we could make B equal to four, and C would be equal to five, because three squared plus four squared is equal to five squared. Three squared, well that's just nine, three times three is equal to nine. Four, four times four is 16. So nine plus 16 is equal to 25, five squared. Well, let's take a copy of our right angle triangle down here and place it directly on the ship. What this shows is if we wanted to get our ship to this point right here, our ship would move across the x-axis here and move up the y-axis here. We can just substitute those names, because remember, the change in the x-value is just the x-velocity, and the change in the y-value is just the y-velocity. If that's confusing, go check out the card on the top right-hand corner and then come back to this tutorial. So refer to our formula down here where we had A squared plus B squared is equal to C squared. Well, C squared is just the speed, remember that's the long side, and that's the same thing as the A squared, which is our x-velocity here plus B squared, which is our y-velocity. Now our change in x is around about two, so that would be two squared. Our change in y-value, well, that's around 1.5. So we go 1.5 squared here, and we need to add those two things together. And I just got the calculator to help us out with that. Two squared, so two times two plus 1.5 times 1.5 is equal to 6.25. But there is an issue with this. 6.25 is actually the speed squared. That's what the two in the top right-hand corner means. It means squared. To find the actual speed, we need to take what's called the square root. Here's a quick recap of the square root. We're gonna use the x-velocity because that's a nice, friendly number. The x-velocity is two, and we know that two squared is just two times two, and that's the same thing as four. So if we wanted to find what the square root is, the square root is signified by this little symbol here. And if we put four in there, we just wanna know what number times itself is equal to the number inside the square root. So what number times itself is equal to four? Well, that's actually two. So two is equal to the square root of four. Let's just do one more example, three squared. You know that as nine, three times three. So the square root of nine is going to be, that's right, it's gonna be three. So to find our speed, we wanna find what the square root of 6.25 is. And the calculator tells me that that number is 2.5. So 2.5 is our speed, and our speed is just the length of the hypotenuse. So our speed here is 2.5. So we can just slightly modify our formula and turn it into speed is equal to the square root of the x-velocity squared plus the y-velocity squared. What we've done to get rid of the square here is take the square root of speed, whatever we do to one side we need to do to the other side. So that's where the square root comes from. Okay, you've been super patient and we're just about to get into scratch. I just wanted to show you the block and scratch that you can use for the square root. So this square root symbol is represented by this scratch operator block and it's square root, sq for square and rt for root. Kind of looks like a square root. And now to tie this all neatly together. So this formula here, speed is equal to the square root of the velocity squared plus y-velocity squared. Well, we can represent that in scratch by creating a variable called speed and we just set speed to the square root of x-velocity times x-velocity plus y-velocity times y-velocity. Let's go do that across in scratch. I'm just over here in scratch. Remember, grab the starter project if you don't have a copy of this already down in the description. Okay, we're gonna make a new variable. Yeah, we're gonna call it speed. After we move the ship, we're going to set speed. We're not gonna set it to zero. We need to go grab that operator and change it from the absolute value to the square value. Remember, we need to add together the x-velocity squared and the y-velocity squared. So we're gonna need some multiplication blocks. Then we wanna get the x-velocity, duplicate it and multiply it by itself. Then grab the y-velocity. You can just grab two of them. And we're gonna put those two values inside the addition operator. And then that whole block, we're going to put inside the square operator. So now when you look up at the screen here in the top left corner of the stage, you'll see we've got speed. And as I click the green flag, I will move the ship around and you can see our ship speed is updated. And notice that it's always positive, which is exactly what speed is. It's positive even when we move down and the velocities are negative. Because remember, a negative times a negative results in a positive. So it's always gonna be positive. The last thing I wanna show you is just what we covered over in Sketchbook. And that's when we square a number when we multiply it by itself. Now I remember that 2.5 times 2.5 was 6.25. What value do you think will result here? That's right, 2.5. I recommend playing around with these values a little bit, changing them around to negative numbers and seeing the result. There you go, there's the positive number. Of course, if you got rid of the negative symbol here, we would result in a negative number. But now we're not multiplying the number by itself, are we? There's two different numbers here. And there you have it. We can get the speed of an object by using Pythagoras' theorem. And we can also use the square root operator to help us out with our calculations. In the next tutorial, we're gonna get our rocket ship turning around and we're gonna be exploring some trig functions to help us out with that. I hope you found this tutorial useful. That's one way that you can use Pythagoras' theorem in real life. Until next time, I'm off to go find a wave. I'll catch you in the next one.