How to Make Cat Follow the Mouse in Scratch

Motion
ラッチ先生
ラッチ先生

Hello!

I’m Teacher Ratch from “Let’s Scratch! Fun Programming Class.”

スック
スック

I’m Sukku.

Nice to meet you!

ラッチ先生
ラッチ先生

Hey, Sukku.

Have you ever played a game where you move things with the mouse like this?

scratch スプライトがマウスの方へ動いていく
スプライトがマウスのほううご
スック
スック

Yeah, I have!

It’s fun, right?

ラッチ先生
ラッチ先生

You can program the cat to follow the mouse

with just 4 code blocks!

スック
スック

Really?

ラッチ先生
ラッチ先生

Here’s the script to make the cat follow the mouse.

「スクラッチしよう!1-4 ネコをマウスで動かそう!」 scratch ネコのスクリプト
マウスでうごかすスクリプト
スック
スック

That’s all you need to make it follow the mouse!

ラッチ先生
ラッチ先生

Now, let’s make it together!

スック
スック

Let’s do it together!!

Now, let’s have fun learning programming!


スポンサーリンク

Here’s the Scratch project we’re making today!

  • Click the green flag and the cat will move!
  • The cat moves toward the mouse!
  • Click the red button and the cat will stop!
スック
スック

Try moving the cat with the mouse!

What you’ll learn in this lesson

1. You’ll learn the script that makes the cat follow the mouse.

「スクラッチしよう!1-4 ネコをマウスで動かそう!」 scratch ネコがマウスの方へついて行く
スプライトがマウスのほうへついて
スポンサーリンク

Let’s look at the script

Here’s the sprite!

「スクラッチしよう!1-4 ネコをマウスで動かそう!」スプライト
スプライト
ラッチ先生<br>
ラッチ先生

The sprite in this Scratch project is:

  • “Cat”
  • I renamed “Sprite1” to “Cat.”

Here’s the script!

Cat’s Script

「スクラッチしよう!1-4 ネコをマウスで動かそう!」scratch ネコのスクリプト
ネコのスクリプト

Let me explain how to program this

Cat’s Script

Programming to make the cat point towards the mouse

scratch ネコがマウスの方へ向くスクリプト
スプライトがマウスのほうくスクリプト
“point towards mouse-pointer” block
scratch 「マウスのポインターへ向ける」ブロック
「マウスのポインターへける」ブロック
  • The sprite points in the direction where the mouse pointer is
scratch 「マウスのポインターへ向ける」ブロックの役目
「マウスのポインターへける」コードの役目やくめ
スック
スック

Hey, what’s a “mouse pointer”?

ラッチ先生
ラッチ先生

The “mouse pointer” is

the arrow on the stage.

スック
スック

Oh, that’s what they call a “mouse pointer”!

Programming to make the cat follow the mouse

scratch ネコがマウスの方へついて行くスクリプト
スプライトがマウスのほうへついてくスクリプト
スポンサーリンク

Let’s change the cat’s movement speed

ラッチ先生
ラッチ先生

Let’s change the cat’s movement speed.

Try changing the number “10” in “move 10 steps” to “5”

Try changing the number in the “move steps” block.
scratch 「10歩動かす」を「5歩動かす」に変える
うごかす」ブロック数字すうじえる
scratch 「10歩動かす」と「5歩動かす」の比較表示
「10うごかす」と「5うごかす」の比較ひかく
スック
スック

Wow! The cat approaches the mouse pointer slowly!

This is easier to control!

ラッチ先生
ラッチ先生

Try changing the number in the “move () steps” block to test different cat movements,

and find the movement you like best!

The cat disappeared when I used “-5 steps”! What should I do?

What happens to the cat’s movement when you use “-5 steps”?

スック
スック

Hey, what happens to the cat’s movement

scratch 「-5歩動かす」ブロック
「-5うごかす」ブロック

when I use “-5 steps”?
Will the cat walk backward?

ラッチ先生
ラッチ先生

Good thinking!
Let’s try it right away!

スック
スック

Huh…?

The cat disappeared!

scratch ネコが画面から消える
ネコの姿すがたえなくなる

It won’t come back even when I press the red button.

The cat won’t appear even when I click the green flag!

What should I do…?!

ラッチ先生
ラッチ先生

Don’t worry! It’s okay!

Because of the -5 steps, the cat runs away from the mouse pointer.

So if you change it back to a positive number like 5 steps,

scratch 「10歩動かす」ブロック
「10うごかす」ブロック

the cat will move toward the mouse pointer and come back!

Change it back to a positive number like 5 steps.
  • The cat appears from the edge
scratch ネコが端から姿を現して出てくる
「〇うごかす」にプラスの数字すうじれると ネコがてくる
スック
スック

Oh! It’s true.

The cat came back. I’m so relieved!

スポンサーリンク

Summary

ラッチ先生
ラッチ先生

oday, we learned

how to program the cat to follow the mouse using the “point towards mouse-pointer” block.

What we learned today

ラッチ先生
ラッチ先生

Programming to make the cat follow the mouse uses these 4 code blocks!

「スクラッチしよう!1-4 ネコをマウスで動かそう!」 scratch ネコのスクリプト
マウスでネコをうごかすスクリプト
ラッチ先生
ラッチ先生

There are many games that use this script to control things with the mouse.

Try using this script to create your own game!

See you next time!!

スック
スック

See you later!!!

(@^^)/~~~

コメント