![]() Next, we will go to Sensing and select ‘Mouse X’ and ‘Mouse Y’. Your X,Y numbers will be different based upon where your character is currently positioned. Inside the ‘Forever’ block, we will place a ‘Glide (1) secs to X (5), Y(10) from Motion. Next, we will add a ‘Forever’ block from Control. Once you have a character selected, click on the Code tab that is right next to Costumes.To build this control, we will begin with a ‘When Green Flag Clicked’ block from Events. You can either draw the character or select one from the Scratch library. ![]() There are times when instead of using keyboard inputs, we want to simply control our character based on the position of the mouse.To begin, select a third character. If we want our character to move faster, we can make the 1 second a number greater than 1 (2-5). So, we will change our X: Pick Random (-240) to (240) and Y: Pick Random (-180) to (180).Finally, if we click the Green Flag, we should see our character move across the screen to a random position every 1 second.If we want our character to move faster, we can make the 1 second a number smaller than 1 (0.1-0.9). In Scratch, the X coordinates range from -240 to 240 and Y goes from -180 to 180. Next, we will go to Operators and select 2 ‘Pick Random (1) to (10)’ blocks.We will place the first ‘Pick Random (1) to (10) block inside of the X coordinate in ‘Glide (1) sec to X(5), Y(10) and the other ‘Pick Random (1) to (10) inside of the Y coordinate.Now, we will need to change the range of the X and Y coordinates. For this example, I’ve selected a butterfly. ![]() By having the computer automatically control movement, then we can engage with our project more actively.To begin, select a second character. For example, if one character is controlled by keyboard inputs then we want another character to utilize computer controls for their movement. There are times when we aren’t going to want precise controls in our projects. And if you press the Up Arrow, Down Arrow, Left Arrow and Right arrow, your character should move in all directions. Now if you press the Green Flag again, you should see all 4 blocks of code outlined in gold (that means they are running).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |