A sprite's direction value controls how much a sprite is rotated. It is measured in degrees (°) and ranges from -180° to 180° (both pointing down). The default value for the direction is 90° (pointing right).
Whether the sprite is actually visually 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
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.
Note: | A sprite's default direction value is 90, which actually represents no rotation. |
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:
direction
— The Stage Monitor and reporter block of the direction value.turn left () degrees
— Changes the direction by a certain amount (counterclockwise version).turn right () degrees
— Changes the direction by a certain amount (clockwise version).point in direction ()
— Sets the direction of a sprite.point towards ( v)
— Changes the direction to point at either another sprite or the mouse pointer.if on edge, bounce
— Changes the direction by -180° when a sprite is touching the edge.move () steps
— Moves in the current direction.[ v] of ( v)
— A block that reports the value of any sprite's X Position, Y Position, Direction, Costume/Background number, Size, Volume and Variables.
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 around really fast, changing the costume, and then slowing it down)
- Making a pong game, that when the ball touches the paddle, it turns -180 degrees