Step 11: Making the ducks stop

To make the ducks stop once they get past a certain point, we'll constantly check their position.

Edit the ducks script, and grab the "Constantly" block (from Events). Drag this block out into the workspace, then grab "if, do" (from Control Flow) and drag it inside.

We want to check if the duck has a y position that is smaller than 150, so grab the "= " block (from Operators) and connect it to the "if" block. Change "=" to "<".

Grab "y position of myself" (stars out as "x position of myself" from Transform), and drag it into the left side of the "<" block. Then grab "0" from Operators, and drag it into the right side. Change 0 to 150.

Lastly, grab a "set velocity" block (from Physics) and drag it inside the "if" block. Set it to "set y velocity to 0" to stop the duck.

Now play that game again. The ducks will move up to 150 y and then have their y velocity set to 0 so that they stop. Next we'll get the ducks hiding.

results matching ""

    No results matching ""