Advanced Movement

Lesson

Advanced Movement

You might have noticed so far that if you try moving in a diagonal, ie an up or down arrow and a left or right arrow. You can only move in one direction at a time when holding them down (try the code below if you haven’t noticed this)

https://scratch.mit.edu/projects/347047265

We can use a repeat until and a key detecting block to make movement a lot more smooth as shown below.

https://scratch.mit.edu/projects/351943667

Have a go playing with the code and try change a previous project you’ve made to allow for smoother movement such as Bee to the Beehive.

Smooth Movement

From the previous lesson, we have learned how to move a sprite by using ‘when the arrow key is pressed, change x or y’. It will allow us to move a few steps by pressing the button each time. However, what if we want to make it go all the way to the direction we want it to go by just press one time? 

We can do that by creating a variable called ‘direction’. And set ‘direction’ to 4 different directions(up, down, left right).

Doing this will create the possibility to have the constant state of going to 4 directions.
Next step we are using a forever loop to check which direction is the one that we select to go when we press the arrow key. 

Test the up arrow key and see if that goes all the way up when you only press once! Now if it works, then it is your turn to complete the rest of the arrow keys.

@

Not recently active