 Scratch motion blocks. They're the blocks that bring your sprites to life. In this Scratchery Basics tutorial, we'll look at the X and the Y of a sprite as well as the direction and rotation, and we'll see what it means to bounce when on edge. Coming up. Hello world, Serving Scratchy here, teacher-serfer programmer bringing you the goodness of learning to code through video tutorials. If it sounds like something that you're into, then consider hitting that subscribe button. Hey, hit the show more button down below to check out the show notes for links that relate to this video. I've also got a link to my funky tee here, Birds of a Feather, which I found on Redbubble. If you click on that link and you purchase this tee or any other, it will support this channel as well as independent artists. So big ups from us to you. But hey, let's kick this tutorial into motion. Alright, we're going to be using this sprite called Modi to help us through this tutorial. We're also using the background from the Scratch online project editor. There's a card in the top-hand corner now coming your way to check that out if you're a bit fuzzy on the project editor. Let's look at our first block, and that is the move block. And what it does is it moves the sprite in the direction that it is currently pointing by this number of steps. So if we look at Modi, Modi is looking across the stage on the X-axis. I remember the X-axis because it looks like a cross and a cross goes across the stage. So it will move Modi across the stage by 10 pixels. Let's click it and you can see here the X-axis, our value here has updated by 10. If I press it again, it is now 20. So it will keep moving in the direction that it's pointing. You'll see if I modify the direction here to zero, it's now pointing up. And if we move 10 steps, Modi now moves up. And our Y value is changing. To check out our next two blocks, I'm just going to jump into a new backdrop. The next two blocks in the motion category refer to the direction that our sprite is pointing. So currently our sprite is pointing in the direction to zero. If we turn it clockwise, that's what this arrow is referring to. If I click it, you'll see that Modi turns in that direction by 15 degrees. Each time we press it, you can see the direction value updating. So currently it's 60. If we press it two more times, it should hit 90. And look, Modi is now pointing in the direction of 90. We can also go backwards any clockwise. And we can go into the negative values as well. Just going to switch back into our other backdrop to look at the next blocks. Okay, let's look at our next block. Go to random position. Which happens when I press this. Modi just goes to a random X and a random Y position on the stage. I'll press it again. And Modi has now gone deeper into the red zone. It's gonna be handy if you're building some enemies for a game. Now you can also specify the exact X and Y position that you want to go to. So you'll see that Modi is currently at this X and Y. And it defaults to those values inside these fields. So we can put Modi back to zero and zero, which is this center point. And once I press it, Modi is back in the center. All right, let's check out these glide blocks. Now these glide blocks are quite neat. It's sort of like an automated move block. What we can do is we can tell Modi to move over a number of seconds to a particular position. So over one second, let's click this, you'll see that Modi just moved to a random position. Just like the go to block, we can specify a specific X and Y value for Modi to go back to. So if we click this block, Modi should take one second to get back to the center of the screen. A disadvantage of the glide blocks is that it pauses the script so no other script can run in the sprite while this is animating. Okay, let's check out the point and direction block. This block is a coded way to modify the direction of the sprite. So down here in the sprite pane, you can modify the direction with this little pop up here. And you can also do the exact same thing by the code. So if I press this block, we should point Modi back in the direction of 90 degrees. All right, so to help us with our next block, I've just got this where the green flag is click block and this forever loop. So we've got this point towards blocks. So what this does is it orient or it points your sprite in the direction of something else. So here it's got the mouse pointer. You can also point in the direction about the sprites if you've got them available. So let's just whack this inside of our third block and watch what happens to Modi now when I move the mouse across the stage. So Modi is now pointing in the direction of the mouse pointer. You can see down here as well, our direction value is updating wherever we move around. So that's quite neat. All right, to help us out with the next blocks, I've just got these four hat event blocks. If you've been fuzzy on event blocks, got a card coming up in the top corner for you right now. So let's check out this change x by 10 blocks. So what that does it remember the x goes across the stage because x is a cross. So if I were to press the right arrow key on my keyboard, we would expect the right to move a cross to the right of the screen. So to do that, we could update the x value by 10. So watch what happens now when I press the right arrow key, you can see Modi is now taking off. Nothing happens when I press the left key. So what I can do is actually duplicate that block. And when I press the left arrow key, we want to change the x in the other direction. So we could subtract 10 pixels by doing that. Now watch what happens when I press the left arrow key, Modi is going back. Same difference goes when we want to change the y value. When press the up key, let's change it by 10. And when we go down, let's subtract 10. And you see Modi returns there. We can also specifically set the x and set the y value just like we did up here. So this go to x and y does it at the same time. But this does only the x or only the y so we can set both x and y back to zero. Okay, let's check out the next block. And that is this if on edge bounce. But this does is it detects when the sprite is at the edge of the screen. And if it does, it flips the sprite in the opposite direction to what it's pointing. So to help us illustrate what this looks like, I've got this when the green flag is clicked hat block and this forever loop attached to it. We're just going to stick this stack block inside of there. I'm going to scroll up and I'm going to get a move 10 steps stack block. So what we're going to do now is going to press the green flag. And Modi is going to go across the stage and watch what happens when Modi reaches the end of the stage. So Modi each time it gets to the end of the stage, the direction is flipping and you can see that down here by the direction value. So currently set to 90 hits the end of the stage and goes to negative 90. Okay, let's check out the last block that we have here and that is set the rotation style. There are three options that you can select from. Now this is just a coded way to do the exact same thing what happens here in the pop up. So you can set the rotation styles way full rotation so all round. And what that does if you move the sprite, you'll see that Modi just rotates all the way around. Now if you set it to left or right, which is this middle option here, what that does is it will just mirror it so it will flip. So currently it's pointing right. See nothing happens when I'm moving it on the right side. But as soon as I flip over 180, then we are now pointing in that left direction. So that is what left right does. And I'm just going to move between those two so you can see what happens there. The last option is do not rotate at all. So you'll see that when I rotate here, it doesn't affect Modi at all. So that's exactly what this does in the code. It just sets those three options through the box. The last three blocks in the motion category are nice and simple. They are reporter blocks and they just tell you the current position. They report back what the current position is of that value. So the current X, the current Y and the current direction. They're pretty useful. You can also flick on these flags for the reporter blocks. So what that does is when you're trying to debug, you can get the values of the sprite on the screen here and it is printed up in the top corner. The last thing I want to mention is sometimes you might get into your scratch project and you do not see any motion blocks. They're missing, you might say. That might be because you're currently in your backdrops and you'll see here that stage selected no motion blocks. So if you ever see that, that's probably why you're not seeing any motion blocks. You're currently in the stage and not on your sprites. It's time for scratchy question and I want to know are you someone who prefers to use direction and steps from coding your projects or do you prefer using the X and Y blocks? Drop your answer in the comment section below. Hey, thanks for checking out this scratch motion blocks tutorial. Like, subscribe, ring that bell if you're around here and have a scout of some of the other content on your screen right now. Hey, if you want to show your support for Surfing Scratcher, check out my Patreon page or go sus out some of these funky teas, links below in the description. But until then, I'm off to go find a wave. I'll catch you in the next one.