The
8 Direction behavior allows an object to be moved up, down, left, right and on diagonals, controlled by the arrow keys by default. It is often useful for controlling the player in a top-down view game. It can also be set to 4 directions or simple up/down or left/right movement which is useful for paddles or sliders.
The 8 Direction behavior is blocked by any objects with the
Solid behavior.
To set up custom or automatic controls, see the
behavior reference summary.
8 Direction properties
Max speedThe maximum speed the object can travel at in any direction, in pixels per second.
AccelerationThe rate the movement accelerates at, in pixels per second per second. When reversing against the current movement, acceleration and deceleration both contribute to slowing down.
DecelerationThe rate the movement decelerates to rest when not being moved, in pixels per second per second. When reversing against the current movement, acceleration and deceleration both contribute to slowing down.
DirectionsSet how many directions the movement can move in. By default it is
8 Directions, allowing movement on diagonals.
4 directions prevents movement on diagonals, and
Up & down or
Left & right only allows movement along a single axis.
Set angleWhether or not the movement should also affect the objects angle.
360 degree (smooth) will always set the object's angle to the current angle of motion.
45-degree intervals will set the object's angle to 8 possible directions.
90-degree intervals will set the object's angle to 4 possible directions.
No means the behavior will not set the object's angle at all, which is useful if you want to control this yourself with events (e.g. to make the object point towards the mouse cursor).
Default controlsIf
Yes, movement is controlled by the arrow keys on the keyboard. Set to
No to set up custom controls using the
Simulate control action. For more information see
Custom controls in the
behavior reference summary.
8 Direction conditions
Compare speedCompare the object's current speed in pixels per second.
Is movingTrue if the object has a non-zero speed (is not stopped). Invert to test if the object is stopped.
8 Direction actions
ReverseInvert the direction of motion. Useful as a simple way to bounce the object off an obstacle.
Set accelerationSet decelerationSet max speedThese set the corresponding properties, described under
8 Direction properties.
Set enabledEnable or disable the movement. If disabled, the movement no longer has any effect on the object.
Set ignoring inputSet whether input is being ignored. If input is ignored, pressing any of the control keys has no effect. However, unlike disabling the behavior, the object can continue to move.
Set speedSet the current speed the object is moving at, in pixels per second.
Simulate controlSimulate one of the movement controls being held down. Useful when setting
Default controls to
No. See
Custom controls in the
behavior reference summary for more information.
StopA shortcut for setting the speed to zero.
8 Direction expressions
AccelerationDecelerationMaxSpeedReturn the corresponding properties, described under
8 Direction properties.
MovingAngleGet the current angle of motion (which can be different to the object's angle), in degrees.
SpeedGet the current object's movement speed, in pixels per second.
VectorXVectorYGet the object's current speed on each axis, in pixels per second. For example, if the object is moving to the left at 100 pixels per second,
VectorX is -100 and
VectorY is 0.