How to Move Cat Left and Right in Scratch

Motion
ラッチ先生
ラッチ先生

Hello!
I’m Teacher Ratch from “Let’s Scratch! A Fun Programming Classroom”!

スック
スック

I’m Sukku. Nice to meet you!

ラッチ先生
ラッチ先生

Today, we’re going to program the cat to move left and right.

ラッチ先生
ラッチ先生

This cat’s movement can be made with just 5 code blocks!

scratchのネコを左右に動かすスクリプト
ネコを左右さゆううごかすスクリプト
スック
スック

Even a Scratch beginner like me can do this!

Let’s have fun learning programming together!


スポンサーリンク

Today’s Scratch Project!

  • Click the green flag to make the cat move.
  • The cat turns around at the edge.
  • The cat doesn’t flip upside down.
  • Click the red button to stop the cat.
スック
スック

Check out the project!

What You’ll Learn Today

1. You’ll learn how to make the cat walk continuously.

scratchのネコが歩きつづける
あるきつづける

2.You’ll learn how to make the cat turn around when it touches the edge.

scratchのネコが端に当たると向きを変えると姿が逆さになる
はしたると、きをえる

.You’ll learn how to keep the cat from flipping upside down when it changes direction.

scratchのネコが端に当たって向きを変えても姿が逆さにならない
さかさまにならない
スポンサーリンク

Let’s Look at the Script

The Sprite for This Project!

「スクラッチしよう!1-1 ネコを左右に動かそう!」のスプライト
スプライト
ラッチ先生<br>
ラッチ先生

The sprite for this Scratch project is “Cat”.
On the Scratch screen, it’s displayed as “Cat”.

 * We changed “Sprite1” to “Cat”.

 Here’s the Script!

Cat’s Script
「スクラッチしよう!1-1 ネコを左右に動かそう!」のネコのスクリプト
ネコのスクリプト

Programming Instructions

Cat’s Script

scratchのネコが左右に歩きつづけるスクリプト
あるきつづけるスクリプト
scratchのネコが端に当たると向きを変えるスクリプト
はしたると きをえるスクリプト
scratchのネコが端に当たって向きを変えても姿が逆さにならないスクリプト
スプライトがさかさにならないスクリプト
スポンサーリンク

What is the “Move Steps” Code?

スック
スック

What does the “move 10 steps” code do?

ラッチ先生
ラッチ先生

The “move ○ steps” code makes the sprite (the cat here) move.

scratch「10歩動かす」コードの役目
「10うごかす」コード役目やくめ
スック
スック

10 steps doesn’t move very far!

ラッチ先生
ラッチ先生

That’s right. 10 steps is a small movement.
You decide how far the sprite (cat) moves with the number.

For example, if you change “10” to “100”, the cat will move much further!

scratch「100歩動かす」コードの役目
「100うごかす」コード役目やくめ
スック
スック

I see!

ラッチ先生
ラッチ先生

However,
with just “move ○ steps”, the cat stops after moving that many steps!

we put it inside the “forever” block.

scratch「ずっと」ブロック
「ずっと」ブロック

When you put it inside the “forever” block, the “move 10 steps” command repeats until you click the red stop button, so the cat keeps walking!

scratchのネコが歩きつづけて端に姿を隠す
スプライトがあるきつづけるスクリプト
スック
スック

Hey, Teacher Ratch!
The cat went too far to the right, and I can only see its tail!

ラッチ先生
ラッチ先生

That’s right.

Since you haven’t clicked the red stop button,
the computer is still receiving commands, but the cat can’t move any further.

And here comes this code!

The “if on edge, bounce” code!

This code changes the sprite’s direction when it touches the edge of the stage!

scratch「もし端に着いたら、跳ね返る」コード
「もしはしいたらかえる」コード

When you put this code inside the forever block, when the cat touches the right edge, it changes direction and keeps walking to the left.

When it touches the left edge, it also changes direction and keeps walking to the right.

The cat will keep walking until you click the red stop button!

scratchのネコが端に当たると向きを変えて歩きつづけるスクリプト
はしたるときをえてあるきつづけるスクリプト
スポンサーリンク

What is the “Set Rotation Style to Left-Right” Code?

スック
スック

Teacher Ratch!
The cat keeps walking, but it flips upside down!

This script doesn’t have the rotation code.

scratchのネコが足に当たって向きを変えると、姿が逆さになる
ネコがはしたってきをえると、姿すがたさかさになる
ラッチ先生
ラッチ先生

Yes!
That’s because when the cat touches the right edge,
it rotates 180 degrees clockwise and moves left!

scratchのネコは右端に当たると右回りに180度回転して姿が逆さになる
右端みぎはしたると、スプライトが回転かいてんして姿すがたさかさになる
ラッチ先生<br>
ラッチ先生

And when it touches the left edge,
it also rotates 180 degrees clockwise and moves right!

scratchのネコは左端に当たると右回りに180度回転して姿が元に戻る
左端ひだりはしたると回転かいてんして姿すがたもともど
ラッチ先生<br>
ラッチ先生

So, we use this “set rotation style to left-right” code!

scratch「回転方法を左右のみにする」コード
回転方法かいてんほうほう左右さゆうのみにする」コード

This code prevents the cat from rotating!
In other words, it tells the computer: “Make the cat face only right or left!”

scratchのネコが左右に歩きつづけても逆さにならないスクリプト
ネコの姿すがたさかさにならないスクリプト
スック
スック

Oh!
Now I understand!

スポンサーリンク

Summary

ラッチ先生
ラッチ先生

Today, we learned programming to “move the cat left and right.”

What We Learned Today

ラッチ先生
ラッチ先生

We learned how to use 5 code blocks.
Let’s review them.

“When Green Flag Clicked” Code

scratch「緑の旗を押されたとき」コード
みどりはたされたとき」コード

When the green flag is clicked, the script below gives commands to the computer.

scratch「緑の旗が押されたとき」コードの役目
みどりはたされたとき」コード役目やくめ

“Move ○ Steps” Code

scratch「10歩動かす」コード
「〇うごかす」コード

Moves the sprite. The number shows how far the sprite moves.

scratch「10歩動かす」と「100歩動かす」コードの比較
「10うごかす」コード「100うごかす」コード比較ひかく

“Forever” Block

scratch「ずっと」ブロック
「ずっと」ブロック

Repeats the code inside until you click the red stop button.

scratch「ずっと」ブロックの役目
「ずっと」ブロック役目やくめ

“If on Edge, Bounce” Code

scratch「もし端に着いたら、跳ね返る」コード
「もしはしいたらかえる」コード

When the sprite touches the edge, it changes direction.

scratchネコが右端に当たったら、右回りに180度回転して姿が逆さになる
「もしはしいたら、かえる」コード役目やくめ1
scratchネコが左端に当たったら、右回りに180度回転して姿が元に戻る
「もしはしいたら、かえる」コード役目やくめ2

“Set Rotation Style to Left-Right” Code

scratch「回転方法を左右のみにする」コード
回転方法かいてんほうほう左右さゆうのみにする」コード

Sets the sprite’s direction to only right or left.

scratchネコの向きを右向きと左向きにする
回転方法かいてんほうほう左右さゆうのみにする」コード役目やくめ
ラッチ先生
ラッチ先生

In today’s programming, we made the cat move left and right continuously.

To do this:

1,Move the sprite (cat)

2,Keep moving the sprite 

3,When it touches the edge, change the sprite’s direction

4,Fix the cat from flipping upside down 

If you think this way, you can create today’s project!

スック
スック

Yay!
Today’s programming is complete!

スポンサーリンク

Try This!

ラッチ先生<br>
ラッチ先生

Try changing the number in the “move 10 steps” code!

 Try “40” or “123”…
Enter your favorite number and see how the cat moves!

「10歩動かす」を「40歩動かす」コードに変える
「〇うごかす」コード数字すうじえる
スック
スック

Hey, Teacher Ratch!
What if I enter “-100”? What will happen to the cat?

ラッチ先生
ラッチ先生

Oh! That’s interesting!
Try entering “-100” right away!

It’s fun to imagine what will happen before you try it!
See if your guess is correct.
Programming is exciting when you test your ideas!


ラッチ先生
ラッチ先生

That’s all for today’s programming lesson!

Did you understand how to move the cat?
As you continue creating projects in Scratch, you’ll learn more about codes and blocks, and understand programming better.

Let’s make lots of projects!
See you next time!

スック
スック

See you!

(@^^)/~~~

コメント