Scratch Primary Lesson 4 Motion and Direction creativecomputerlab.com
Motion and Direction In this session we re going to learn how to move a sprite. Go to http://scratch.mit.edu/ and start a new project:
The move Block Go to the palette. Drag the block onto the cat sprite s script area. Click on it and watch the cat move to the right:
Move With The Arrow Keys Go to the palette. Drag the block onto the script area. Choose the right arrow key: Connect the right arrow key to the move block: Press the right arrow key and watch the cat move. creativecomputerlab.com
Move With The Arrow Keys Let s do the same for the left arrow: Here s a cool trick! Right click on the block and select duplicate Change the duplicate to left arrow : We ve easily created another set of scripts Place the left arrow script on the left creativecomputerlab.com
Move With The Arrow Keys Move the cat with the left and right arrow keys: The left arrow key is moving to the cat to the right as well. How can we make the cat go left??
Move With The Arrow Keys We want the left arrow to move in the opposite direction of the right arrow:? What kind of a number do we have to put into the left arrow move block?
Move With The Arrow Keys A negative number moves in the opposite direction as a positive number. Positive numbers move to the right -> Negative numbers move to the left <- Try it and see!
Move Up and Down Create move scripts for the up and down arrow keys. You can duplicate them easily.?? What numbers do we put into the move blocks for the up and down directions?
Direction The reason the cat can move left and right is because it is pointing in a certain direction In Scratch, when sprites are first created, they are set to point towards 90 degrees. Click on the blue i on the cat sprite. It will show information about the sprite. You can see in which direction the sprite points:
See which way it moves with the left and right arrow keys. creativecomputerlab.com Direction Experiment Let s change the direction of the cat, then move left and right with the arrow keys and see what happens: Go to the palette and drag out the block onto the script area. Set the direction to 0 degrees: Double click on the block to make it work. The cat is now facing up, it s direction is 0 degrees:
More Direction Experiments Change the cat s direction to different degree values, then press the arrow keys and see what happens: See what happens when the direction is set to -90 degrees: Which way do the left and right arrow keys move the sprite when it is pointing towards -90 degrees?
The Degrees of the Circle In Scratch, direction is the same as the degrees of the circle: 360-90 or 270 90-180 0 and 360 degrees are at the top. They both point up. 180 degrees is half the circle. It points down. In Scratch, the left half of the circle is expressed in negative numbers. Also -180 and 180 are the same. creativecomputerlab.com
All Four Directions In order to make all four arrow keys make the sprite move in the correct direction, we need to set the direction for each key. Try this: Why don t we need to move with negative numbers anymore? How do we keep the sprite from going upside down when going left? creativecomputerlab.com
Rotation Styles You can control which way the cat is facing when changing direction with blocks or by setting the rotation style for the sprite: The cat rotates all around the circle. It goes upside down when degrees are negative. The cat stays right side up all around the circle. It also stays level. creativecomputerlab.com The cat stays facing the same way around the circle. It doesn t rotate.
Facing the Right Way In order for the sprite to face the way it is moving, the correct rotation style must be chosen for the direction. For left (-90) and right (90) use For up (0) and down (180) use
Do the Walk The cat comes with two animation costumes: Lets make the cat take steps when moving. Add the block to each script:
Animate Other Characters Many Scratch sprites come with several costumes which can make an animation when played in a sequence. For example, the Boy3 Walking sprite has 5 costumes which can animate his walk: Choose the Boy3 Walking sprite and add him to your project:
Copy Scripts to Another Sprite We want to animate the boy like we did with the cat. BUT we don t want to make the same scripts all over again. We can copy the scripts from the cat: 1. Go to the cat s script area 2. Select a script block and drag it over to the Boy3 Walking sprite icon: 3. Let go of the mouse button. The script flies back to its place. 4. Check the Boy s script area. You should see the script copied there. 5. Do the same for the other scripts. Now the boy can walk using the arrow keys. You can hide the cat if you want to. creativecomputerlab.com
Make Games and Stories Now that you can make sprites walk around the stage, think about all the games and stories you can make! Have a look at all the sprites and backgrounds and use your imagination!