Scratch ProjectsJuaraKu
HomeLogin

Step 5 of 8

63%

Improved movement

The dragonfly 'glitches' and changes direction really fast if the mouse-pointer is touching the dragonfly. You will check another condition to fix this.
![The Stage showing an insect and dragonfly.](images/improved-movement.png "width:300px")

Select the Dragonfly and find the script that starts with when flag clicked.

Drag an if inside the forever block. The blocks inside the forever will move inside the if.

when flag clicked
set size to [25] %
forever
+if < > then
start sound [Wings v]
point towards (mouse-pointer v)
move [5] steps
end
end

Then drag a not block into the if and a touching (mouse-pointer) inside that.

when flag clicked
set size to [25] %
forever
+if <not <touching [mouse-pointer v] ?> > then
start sound [Wings v]
point towards (mouse-pointer v)
move [5] steps
end
end

Test: Check that the glitch is fixed, and the Dragonfly only moves when it is not touching (mouse-pointer).

Try a different condition that makes the dragonfly move when it is far enough from the mouse-pointer:

<(distance to [mouse-pointer v]) > [50]>

Save your project