Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

5. Keep Moving

Transcript

You probably noticed your hero currently looks like it never stops walking!

The looks loop doesn’t know whether or not the hero is moving forward.

This video will fix that!

Make a variable.

Your first variable should’ve been called “up/down speed” or something like that.

This variable will keep track of the same thing, but in the left/right direction.

Call it “left/right speed” or “x speed,” or whatever makes sense to you.

Click “OK.”

In the looks loop, make it animate only if the x speed is not zero.

Snap an “if” block around everything in the loop.

To make the condition “left/right speed does not equal zero,” use two “operators” blocks: First put a “not,” then inside place an “equals.”

Type 0 into one side of the “equals” block, then, from “data,” snap the new variable into the other side.

Look at the motion loop, and find something that will communicate to the looks loop that the hero is moving.

Use the broadcasted message “forward” to communicate whether the hero should do its walking animation.

From “events” grab another “when I receive” block, and choose “forward” from the dropdown.

Under your new event block, set the variable to 1 to indicate that it’s moving.

It’s a little tricky because there’s no message to say “stop moving forward,” but you do know that the “forward” message keeps getting sent as long as the hero is moving.

So, just wait!

If the message doesn’t get sent again, the hero has stopped moving.

Below the “set variable” block, snap a “wait” block, then another “set variable” block, where you’ll set the left/right speed back to 0.

Tinker with the value in the “wait” block and test – a small value is probably best.

The example will use 0.1.

Great!

The hero looks like it’s walking only while it’s actually moving forward.

Now, it’s your turn.

Add a new variable “left/right speed.”

Make the conditional “if left/right speed is not 0,” then snap all the looks loop blocks inside.

When the hero receives “forward,” have it set their left/right speed to 1, wait for a short time, then set the left/right speed back to 0.

arrow_backward Back
Next arrow_forward
Instructions
  1. Add a new variable "x speed."
  2. Make the conditional "if x speed is not 0," then snap all the looks loop blocks inside.
  3. When the hero receives "forward," have it set the x speed to 1, wait for a short time, then set the x speed back to 0.