Presentation is loading. Please wait.

Presentation is loading. Please wait.

Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.

Similar presentations


Presentation on theme: "Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University."— Presentation transcript:

1 Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University June 2009

2 Introduction and Setup This tutorial will demonstrate how to teach a character to walk to any object in a world by using parameters. It will also show how to copy that same character, including the new walk skill, into a new world using inheritance. Open a new Alice snow world. Click on Add Objects. Choose Local Gallery, and click people. Add one of each into your world: EskimoGirl, Snowman, SnowWoman. Place the characters so there is some space between them and they are facing the camera. Let's get started by setting up the first world.

3 Enter in 0.15 and click Okay Now roll the leftUpperArm to the left by 0.15 revolutions. We now need to move the eskimoGirls arms down. In the object tree click on eskimoGirl and the right click on rightUpperArm. Under methods go to eskimoGirlrightUpperArm roll, right and other... Click the green Done button when finished Introduction and Setup

4 Now we will teach eskimoGirl to walk toward the snowman. To do this we will create a new method that will have her face the snowman, turn her arms and legs and move forward until she reaches him. Step 1: Teaching eskimoGirl to walk Lets start by creating a walk method. Click on eskimoGirl in the object tree. In the details area click on the methods tab and click on create a new method Name the new method: walk.

5 The first action eskimoGirl needs to perform is to turn and face where she will be walking. Step 1: Teaching eskimoGirl to walk Continued... Under the eskimoGirl methods, click on turn to face and drag into the methods edit area. Choose the entire snowman.

6 Next let's work out how eskimoGirl's arms and legs should move to create a walking motion. If you watch someone walking on a treadmill their right leg moves forward with their left arm, while their left leg and right arm appear to move backwards. First add a Do together block to the method. Then add the right leg movement. Select rightUpperLeg under the eskimoGirl in the object tree. Drag and drop the turn method into the Do together block. Select forward and enter in 0.1 revolutions. Step 2: EskimoGirl's First Step

7 Add in the other methods for arm and leg motions, and move eskimoGirl forward. Your method should look similar to this. Step 2: EskimoGirl's First Step Continued...

8 To see how this method works, click on world.my first method then drag and drop the walk method into the method edit area. Click on play to see what happens. Step 2: EskimoGirl's First Step Continued...

9 Now lets bring eskimoGirl's arms and legs back into the standing position to complete the first step. To do this we need to go back to the walk method and add the next Do together block. Note: You may notice that the right leg looks like it is going backward, when the instructions say forward. This is based on how this object was originally set up by the Alice developers. It will not affect the walking method as long as you keep the directions consistent Step 2: EskimoGirl's First Step Continued...

10 Complete the Do together block by adding the leg and arm movements and reverse their direction. Your control statement should look similar to this. Go ahead and play the world to see eskimoGirl's first step. Step 2: EskimoGirl's First Step Continued...

11 For the second step we want to bring the left leg forward and then complete the step by bringing the right leg forward. Let's take a short cut and copy the control statements we already have. To make a copy of the do together that moves the left leg forward, right click on the do together box and select make copy. You can then drag and drop the new do together to where you want it to go. In this case move it to the end of the method. Step 3: EskimoGirl's Second Step

12 There is another way to make a copy of a control statement by using the clipboard. Let's make a copy of the Do together block that moves the right leg forward. Drag and drop the block onto the clipboard at the top right hand side of the window. The clipboard will now have a white paper on it to show something is ready to be pasted. Step 3: EskimoGirl's Second Step Continued...

13 To paste from the clipboard, drag and drop the white paper from the clipboard to where you want it in your method. In this case you want to place it at the very end of the method. Now play the world to see eskimoGirl take two steps toward the snowman. Step 3: EskimoGirl's Second Step Continued... Note: If eskimoGirl has already reached the snowman, go into add objects and move eskimoGirl farther away.

14 Now we want eskimoGirl to walk to the snowman by repeating the control statements over and over again until she reaches the snowman. Rather than simply copying the statements again and again we can use a Loop or a While statement. Step 4: Completing the Walk Method Let's use the While statement so the eskimoGirl can walk while she has not yet reached the snowman. Drag and drop the While control statement to the top of the walk method and select true.

15 Under eskimoGirl's functions drag is at least away from to the true on the While statement. Select 1 meter away from the entire snowman. Step 4: Completing the Walk Method Continued...

16 Now drag and drop all the control statements we have made into the While loop. Be sure to do them in order. Play your world and watch the eskimoGirl walk all the way to the snowman. Note: You may have to adjust the is at least number to have the eskimoGirl stop where you want her to. Step 4: Completing the Walk Method Continued...

17 Now lets change the walk method to be more flexible so we can use it to have eskimoGirl walk to any object we choose. To do this parameters can be added. A parameter is like a basket that receives information that we send to a method. We will use parameters to tell the walk method where we want eskimoGirl to walk to and how close we want her to get. Then we can ask her to walk to within 1 meter of snowman or within 1 meter of snowWoman using the same method. Step 5: Creating parameters parameter information

18 There are many different types of information a parameter can hold including, Numbers, Objects and Booleans. Numbers can be positive or negative and include decimals. Objects include anything that can be listed in the object tree. Boolean (pronounced ˈbü-lē-ən) is a special type that can only be TRUE or FALSE. IMPORTANT: parameters can only hold one piece of information and it must be the exact type of information it was designed to hold. Note: We won't be exploring boolean in this tutorial, but this type can be helpful when you are exploring parameters in the future. Step 5: Creating parameters Continued...

19 So lets get started.... First, create a parameter to hold the information on which object eskimoGirl should walk to. Click on create new parameter. In the pop-up box enter in the name destination, and select the type Object. This means we only want to accept information about the object in this parameter. Click on OK to create the new parameter Step 5: Creating parameters Continued...

20 Notice how the parameters show what type of information they are expecting: an object, or a number Next create a parameter to hold the information about the distance. This is the distance from the object to the eskimoGirl. Click on create new parameter. In the pop-up box enter in the name distanceFrom, and select the type Number. This means we only want to receive information about a number in this parameter. Click on OK to create the new parameter Step 5: Creating parameters Continued...

21 Now let's replace the parts in the method that specifically mention the snowman with the destination parameter. There are two places. Drag the destination parameter over the word snowman in the While statement Drag the destination parameter over the snowman word in the turn to face statement and select destination. Step 6: Adding Parameters to the Method

22 You have now added parameters to your method. However, you will not be able to play your world. Go to my first method and take a look at what has happened to the method. Now drag the distanceFrom parameter over the 1 meter word in the While statement Step 6: Adding parameters Continued...

23 In my first method the eskimoGirl's walk method now shows the two parameters that were added. We need to send these parameters the correct information before the world can be played. Click on the destination and select the entire snowman. The distanceFrom default number is 1. Let's leave this number for now. Step 6: Adding parameters Continued...

24 Now we can have the eskimoGirl walk to any object in our world. Add another eskimoGirl walk method to my first method and select the entire snowWoman with a distanceFrom of 1. Play your world and see what happens. Note: You may have to adjust the distanceFrom amount to have the eskimoGirl stop where you want her to. Step 6: Adding parameters Continued...

25 EskimoGirl is now tired of the snow and wants to go to the beach. The rest of this tutorial will show you how save our new eskimoGirl and bring her into a beach world. Let's rename eskimoGirl to show that she can perform more skills. Step 7: Inheritance In the object tree right click on eskimoGirl and select rename. Change the name to cleverEskimoGirl

26 To add the new cleverEskimoGirl into a different Alice world we need to save her as a new 3D model class. Okay, let's take a step back so we can figure out what a class is all about. Perhaps you noticed that the objects in the Gallery are called a class. Step 7: Inheritance Continued... A class is a specific kind of object. Every object that comes from this class knows how to do the same things, it has the same methods. For example we only needed to teach cleverEskimoGirl how to do one thing, walk. She already knew how to do all the things the class eskimoGirl knew how to do. CleverEskimoGirl inherited all the properties and methods from the class eskimoGirl. Inheritance is when a new class is based on a class that already exists.

27 To save cleverEskimoGirl as a new class, right click on cleverEskimoGirl and select save object... Save the file in a place where you can find it later. To use the cleverEskimoGirl in a new world we need to save the her as a new 3D model class. This means a copy of cleverEskimoGirl, can be added into a new world. Step 7: Inheritance Continued...

28 While in the add objects window you will add an object of the cleverEskimoGirl. Under the File menu at the top right of the window select Import... Find the file called cleverEskimoGirl and select it. Position the objects to look something like this. Start a new sand world, and add two beachChair objects from the beach gallery Step 8: Importing from a new Class

29 Under the cleverEskimoGirl methods add walk into the my first method. Have the cleverEskimoGirl walk to each beachChair with a distanceFrom of 1.5 Now play your world and watch the cleverEskimoGirl walk to each beachChair. Step 9: Finishing Up


Download ppt "Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University."

Similar presentations


Ads by Google