$$ \newcommand{\floor}[1]{\left\lfloor{#1}\right\rfloor} \newcommand{\ceil}[1]{\left\lceil{#1}\right\rceil} \renewcommand{\mod}{\,\mathrm{mod}\,} \renewcommand{\div}{\,\mathrm{div}\,} \newcommand{\metar}{\,\mathrm{m}} \newcommand{\cm}{\,\mathrm{cm}} \newcommand{\dm}{\,\mathrm{dm}} \newcommand{\litar}{\,\mathrm{l}} \newcommand{\km}{\,\mathrm{km}} \newcommand{\s}{\,\mathrm{s}} \newcommand{\h}{\,\mathrm{h}} \newcommand{\minut}{\,\mathrm{min}} \newcommand{\kmh}{\,\mathrm{\frac{km}{h}}} \newcommand{\ms}{\,\mathrm{\frac{m}{s}}} \newcommand{\mss}{\,\mathrm{\frac{m}{s^2}}} \newcommand{\mmin}{\,\mathrm{\frac{m}{min}}} \newcommand{\smin}{\,\mathrm{\frac{s}{min}}} $$

Prijavi problem


Obeleži sve kategorije koje odgovaraju problemu

Još detalja - opišite nam problem


Uspešno ste prijavili problem!
Status problema i sve dodatne informacije možete pratiti klikom na link.
Nažalost nismo trenutno u mogućnosti da obradimo vaš zahtev.
Molimo vas da pokušate kasnije.

Motion

You already got to know the Scratch user interface, you learned how to create sprites and determine their position on the stage. Now is a perfect time to learn how to move them by using commands (blocks) from the category Motion. These blocks will enable you to make simple games and animations.

There are 3 types of blocks you can use to move your sprite:

  • Blocks for absolute motion

  • Blocks for relative motion

  • Other motion blocks

Blocks for absolute motion

In the category Motion, there are 4 blocks, which enable absolute motion.

_images/AKBlokovi.png

You will use these blocks when you need to program your sprite to move to a specific location (point) on the stage.

The cat is chasing the mouse…

The cat is located in the center of the stage, and the mouse is in the point (x:150 y:100).

_images/MM1.png

We remind you that the stage is a rectangular surface 480 pixels wide and 360 pixels high. The center has the coordinates (x:0 y:0).

If you want the cat to catch the mouse you can just use the block AK1.

_images/MM1a.png

If you want the chase to last longer, you can use the block AK2. With this block the cat will glide for 1 second from the point (x:0 y:0) to the point (x:150 y:100).

By using the blocks AK3 and AK4 you can make it seem like the cat is slowly sneaking up to the mouse:

_images/MM34a.png

You can always see the current position of the sprite (the current values of x: and y:) below the stage, in the sprite list.

_images/XY.png

    Q-5: Analyze the position of the mice presented in the figure below and select the program, which will allow the cat to “catch” all the mice.

    _images/AKZ1.png
  • Program A
  • Well done! The cat "caught" all the mice!
  • Program B
  • Hm.. We recommend that you carefully read the lesson Position of the sprite on the stage.

Vazno So, by using the blocks for absolute motion, you tell your sprite exactly where it should go on the stage.

Blocks for relative motion

Relative motion is not determined by the location the sprite should go to, but by the current position of the sprite.

In the category Motion, you have at your disposal several blocks, which enable relative motion.

_images/RKBlokovi.png

In the example where the cat was chasing the mouse, we knew the exact location of the mouse (the point in which it is located). The situations where we do not know the sprite’s location are more common. In these cases, we will use blocks for relative motion to move our sprites.

When it comes to relative motion, it is very important to point (turn) the sprite in the desired direction. We achieve this by dragging the arrow around the circle of the block RKS2.

It is good for you to know that direction toward 0 represents up, toward 90 is to the right, toward 180 is down, and toward -90 is to the left.

_images/RKS1.png

You can always see the current direction of the sprite below the stage, in the sprite list in the field Direction.

_images/XY.png

    Q-6: Analyze the program presented in the figure, and select what you think is the direction of the sprite, as well as what will be its position after the program finished running.

    _images/RKZ1.png
  • Direction: 90 (right) Position: (x:50 y:-100)
  • Analyze the program again. Does turning the sprite 90 degrees change its direction?
  • Direction: 180 (down) Position: (x:50 y:100)
  • Well done! You understand the movement of the sprite well!

Vazno So, by using blocks for relative movement, you tell the sprite where to point and move relative to its current position.

Other motion blocks

In the category Motion, you have 4 more blocks at your disposal, which enable sprites to move.

_images/OKBlokovi.png

The stage is a limited space. When the sprite reaches the edge of the stage, it would be natural for it to turn around and continue moving in another direction. You will enable this behavior of the sprite by using the block OK3. You will also decide how the sprite continues to move. If within the block OK4a you set the rotation style of the sprite to all around, it will continue to move upside-down. This will not happen if, from the drop-down list of the block, you choose the option left-right OK4b.

_images/OKRub12.png

You can always see the current style of your sprite’s movement below the stage in the sprite list, in the field Direction.

_images/XY.png

Let’s go back to our sprites: macka and mis.

If we do not know the exact position of the mouse, and we want the cat to point toward it (turn toward it), we can use the block OK1. We just need to select the Mouse sprite OK1a from the drop-down list, and the problem is solved.

We will show you how the last two blocks work in the following example.

The cat is chasing the mouse…

The cat is chasing the mouse, gliding toward it. The mouse constantly turns and goes toward the cursor, which we are moving around the stage.

_images/OKPR1.png

Above each of the sprites are scripts that enable the described behavior.

Izazov Upgrade the program presented above by adding one more sprite - an apple. Have the mouse chase the apple and the cat chase the mouse. Make the apple move toward the cursor (which we control), the mouse should move toward the apple, and the cat should move toward the mouse.

_images/MMJ.png

Possible solution: