Direction (value)

Scratch Cat changing directions (and moving, to see differences) 36 times, changing direction by 10 degrees each time.
A sprite's direction value controls how much a sprite is rotated. It is measured in degrees (°) and ranges from -90° (pointing left) to 180° (pointing down). The default value for the direction is 90° (pointing right).

Whether the sprite is actually rotated or not is determined by the sprite's rotation style.

Depending on the direction a sprite is pointing in, the Move () Steps block will move the sprite differently. However the Change X by () and Change Y by () blocks are not affected by the direction of a sprite.

Directions

The direction system Scratch uses.

Scratch uses an angle measurement that is similar to degrees, with the addition of negative values, like polar coordinates. "0" represents "up". Every degree added corresponds to a one degree turn clockwise by the sprite. So a direction of 90 means a sprite turns 90 degrees (a quarter turn) after pointing straight up and will thus point right.

Negative degree measures simply mean rotation counter-clockwise rather than clockwise. So -90 is left and -180 is down, just like +180.

This table shows some common values and their directions:

Degrees Direction
-360, 0, 360 Up
-270, 90 Right
-180, 180 Down
-90, 270 Left

Finally, when the direction is greater than 360°, the sprite points in the direction, minus 360°. So 400° is analogous to 400-360=40°, and 720° = 360° = 0°. This can be mimicked by the code below.

The expression that returns the direction (subtracting the 360 if the number is too large) is this:

((((180) + (x)) mod (360)) - (180))

Related Blocks

The following blocks can be used in conjunction with this value:

Example Uses

This value can be used in a number of ways:

  • Spinning an object in a game
  • Making a sprite point at the mouse pointer or another sprite
  • Can be used to give the illusion that a sprite is turning into something else (i.e. spinning it round really fast, changing the costume, and then slowing it down)

See Also

  • This page was last modified on 26 January 2014, at 05:58.