How to Make a Virtual Pet in Scratch | Tutorial

Alphabets Sounds Video

share us on:

In this lesson, students learn how to create a virtual pet using Scratch, starting with selecting a pet and backdrop, then programming interactions such as greetings, animations, and feeding. The tutorial guides learners through adding features like hunger tracking and encourages them to expand their project with additional elements like toys and day-night cycles. By the end, students will have a functional virtual pet simulator that they can customize and enhance.
  1. What kind of pet did you choose for your virtual pet, and why did you pick that one?
  2. How does your pet greet you when you start the game?
  3. What happens when you feed your pet, and how do you keep track of its hunger?

How to Make a Virtual Pet in Scratch

Hey there! Today, we’re going to learn how to make a super cool virtual pet using Scratch. A virtual pet is like a fun digital friend that you can play with, feed, and take care of. Let’s dive in and create our very own virtual pet simulator!

Step 1: Choose Your Pet

First, we need to pick a pet. You can draw your own pet, upload a picture, or choose a character from Scratch. Click the “choose a sprite” button and select any pet you like. It could be a dragon, a rock, or even a dog. For this tutorial, let’s choose a hedgehog. Now, let’s pick a backdrop for our pet’s home. How about a garden?

Step 2: Introduce Your Pet

Let’s make our pet say hello! In the “Looks” category, find the “say” block and write a message for your pet. To make this happen when we start the game, add a “when green flag clicked” block on top. Now, every time you click the green flag, your pet will greet you!

Step 3: Animate Your Pet

Time to bring your pet to life with some animation! Use the “switch costume” block to change your pet’s pose. Drag out two “switch costume” blocks and choose different poses. Connect them with a “wait” block set to 0.2 seconds. To make the animation repeat, use a “repeat” loop and set it to repeat twice. Add a “wait” block after the second costume switch to make it smooth. Finally, add a sound by choosing one from the “Sounds” tab and using the “start sound” block.

Step 4: Interact with Your Pet

Let’s make the animation play when you click on your pet. Use the “when the sprite clicked” block to trigger the animation. Now, every time you click your pet, it will move and make a sound!

Step 5: Feed Your Pet

Now, let’s feed our pet. Choose a piece of food, like an apple, and add it to your project. Use the “when this sprite clicked” block so that when you click the apple, your pet will come over. To make this happen, use a “broadcast” message called “Food.” This is like sending an invisible message to your pet.

On your pet, use the “when I receive Food” block to make it respond. Instead of saying something, let’s make it glide to the apple. Use the “glide to” block and select the apple. After reaching the apple, add a “chomp” sound and wait 0.5 seconds before gliding back to its original spot.

Step 6: Track Hunger

Let’s keep track of how hungry our pet is. Create a variable called “hunger.” The higher the number, the hungrier your pet is. If it’s 100, your pet is very hungry, and if it’s zero, it’s not hungry at all.

To make your pet get hungrier over time, use the “change hunger by one” block inside a “forever” loop. Add a “wait” block set to five seconds to slow down the hunger increase. When the game starts, set the hunger to zero.

When your pet eats the apple, decrease the hunger by one using “change hunger by -1.” This will make your pet less hungry when it chomps on the apple.

Explore More!

Now you can feed your pet and keep it happy! You can add more fun items like a ball or a toy for your pet to play with. You could even add more variables like thirst and fun to make sure your pet is always feeling great. Try adding day and night cycles, a sleeping animation, or even more pets. The possibilities are endless!

Have fun creating your virtual pet, and happy scratching!

  • What kind of pet would you choose to create in Scratch, and why? Can you think of any special features or tricks you would like your virtual pet to have?
  • Have you ever taken care of a real pet or plant? How is taking care of a virtual pet similar or different from taking care of a real one?
  • Imagine your virtual pet could talk to you. What do you think it would say, and what kind of adventures would you like to go on together?
  • Design Your Own Pet Habitat: Imagine your pet lives in a special place. Draw a picture of where your pet would live. Would it be in a magical forest, a cozy house, or a sunny beach? Use crayons, markers, or colored pencils to bring your pet’s home to life. Share your drawing with your classmates and explain why you chose that habitat for your pet.

  • Pet Care Journal: Create a journal to track how you take care of your virtual pet. Each day, write or draw what you did to keep your pet happy and healthy. Did you feed it, play with it, or teach it a new trick? At the end of the week, share your journal with a friend and discuss what you learned about taking care of a pet.

  • Pet Behavior Observation: Spend some time observing a real pet, like a dog, cat, or even a bird. What do they do when they are hungry, happy, or tired? Write down or draw your observations. Then, think about how you can use these behaviors to make your virtual pet more realistic. How would your virtual pet show it is hungry or happy?

Sure! Here’s a sanitized version of the YouTube transcript:

Hi everyone, it’s Zoë from the Scratch team, also known as Zinnea. Today, I wanted to show you how to make a virtual pet in Scratch—a pet you can interact with, take care of, and give food to. In this tutorial, I’ll guide you through creating a virtual pet simulator, where you can introduce your pet, animate it, feed it, and keep track of how hungry it is. Let’s get started!

First, let’s pick a pet and introduce it. You can draw your own pet, upload an image, or choose one of the characters available in Scratch by clicking the “choose a sprite” button. You can select any pet you like, such as a dragon, a rock, or a dog. I will choose a hedgehog. Now, let’s also select a backdrop. It can be any setting you prefer; I will pick a garden backdrop.

To introduce our pet, let’s have it say something. In the Looks category, you can drag out a “say” block and write a message for your pet. It would be nice if this happened whenever we click the green flag, so we can add a “when green flag clicked” block on top. Great!

Next, let’s animate our pet so it can perform a little animation. To animate a character in Scratch, you can switch between different poses using the “switch costume” block. If I drag out two “switch costume” blocks and select different poses, I can create an animation. Let’s connect these blocks with a “wait” block in between, setting it to wait 0.2 seconds.

To make the animation repeat, we can use a repeat loop. I’ll set it to repeat twice. It repeated, but it looked a bit glitchy, so we need to add another wait block after the second costume switch. Almost done with our animation! To finish it off, let’s add a sound. You can go to the Sounds tab, click the “choose a sound” button, and select a sound you like. To make it play, we just need to add a “start sound” block on top.

Now, let’s add a “when the sprite clicked” block so that we can trigger this animation every time we click the sprite. There we go! You’ve animated your pet.

Next, let’s feed our pet. By the end of this section, we will create a piece of food, and when we click on it, the pet will go over, take a bite, and then return to its original position. Let’s add a piece of food—I’ll choose an apple. We need to drag out a “when this sprite clicked” block so that when we click the apple, the hedgehog will come over.

To tell the hedgehog to come over to the apple, we can use a broadcast. A broadcast is like an invisible message that one sprite sends out, prompting another sprite to do something specific. Let’s make the apple broadcast a message called “Food.”

Now, to make the hedgehog respond to that message, we can click on the hedgehog and use the block “when I receive Food.” To check if it’s working, I’ll have it say something when it gets the broadcast.

Great! We can click on the apple, it sends out the broadcast, and the hedgehog receives it. However, instead of having the hedgehog say something, we want it to glide over to the apple. We can do this by dragging out the “glide to” block and selecting “apple.”

Now, let’s make it glide back to its original position. In Scratch, you can specify the X and Y coordinates for your sprite. If you don’t know what X and Y are, X represents the horizontal position, and Y represents the vertical position on the screen.

Here’s a handy trick: drag your sprite to where you want it to glide, and the “glide” block will update to that specific X and Y. Now, let’s add a bite sound when it reaches the apple. After it gets to the apple, I’ll have it play the chomp sound, wait 0.5 seconds, and then glide back.

Now we can feed our pet! Lastly, let’s make our project keep track of how hungry our pet is, so you need to keep feeding it. To do this, let’s create a variable called “hunger.” The larger this number is, the hungrier our pet is. If it’s 100, our pet is very hungry, and if it’s zero, it’s not hungry at all.

We want the hedgehog to get hungrier over time. We can use the “change hunger by one” block to increase the hunger level. To ensure the hedgehog is always getting hungrier, we can place this inside a “forever” block.

To slow down the rate of hunger increase, let’s have it wait five seconds before changing the hunger by one. Now the hunger is increasing at a nice pace, but we should set the hunger to zero when the project starts.

Next, we want the hunger level to decrease when the pet eats. We can change the hunger by negative one to make the hedgehog less hungry. Let’s have this happen when it chomps on the apple.

Now, let’s test it out. The hunger starts at one, and when we click on the food, it goes back down to zero. There you go! Now you can feed your pet to keep it from getting too hungry.

You can take this project in many directions. Just like we added the apple, you could add more items for your pet to interact with, like a ball or a toy. You could also introduce more variables, such as thirst and fun, and ensure they all stay at a good level. You could add day and night cycles, a sleeping animation, or even multiple pets. I’m excited to see all the things you create!

Anyway, I’ll see you next time, and happy scratching!

This version maintains the instructional content while removing any informal or extraneous language.

All Video Lessons

Login your account

Please login your account to get started.

Don't have an account?

Register your account

Please sign up your account to get started.

Already have an account?