The
Custom Movement behavior does not directly implement any movement for an object. Instead, it provides features that make it easier to implement your own "custom" (event-based) movement.
The way different movements are made is out of the scope of this manual section. Instead, it will outline the basics of the Custom Movement behavior and what its features do. For an example of Asteroids style movement using the Custom Movement behavior, see
Custom movement (asteroids).capx in the Examples folder in Construct 2's install directory.
For many games, the built-in behaviors like Platform and 8 Direction are perfectly sufficient. Recreating existing behaviors with the Custom Movement should be avoided, since movements are difficult and time consuming to implement correctly. The built-in behaviours have been thoroughly tested, probably have more features than you imagine (like slope detection in Platform), and are much quicker and easier to use than making your own movement.
Overview of custom movements
Most movements in Construct 2 work by manipulating two values: the speed on the X axis (
dx) and the speed on the Y axis (
dy). These are also known as
VectorX and
VectorY in some other behaviors. For example, if an object is moving left at 100 pixels per second,
dx is -100 and
dy is 0. The object can then be accelerated to the right by adding to
dx. This is also how most of the other movement behaviors that come with Construct 2 work internally (like Platform and 8 Direction).
The Custom Movement behavior stores the
dx and
dy values for you, and provides features that help easily implement the math and algorithms necessary to make a movement.
Every tick the Custom Movement adjusts the object's position according to the
dx and
dy values. This is called a
step. The Custom Movement can also use multiple steps per tick, which can help detect collisions more accurately if the object is moving very quickly. Each step will trigger
On step,
On horizontal step or
On vertical step depending on the
Stepping mode property.
Custom Movement properties
Stepping modeHow to step the movement each tick. The number of steps taken (if not
None) depends on the
Pixels per step property.
None simply steps the object once per tick according to its velocity.
Linear will step the object in a straight line towards its destination position, triggering
On step.
Horizontal then vertical will step the object to its destination first on the X axis (triggering
On horizontal step), then on the Y axis (triggering
On vertical step).
Vertical then horizontal will step the object to its destination first on the Y axis (triggering
On vertical step), then on the X axis (triggering
On horizontal step).
Pixels per stepIf
Stepping mode is not
None, this is the distance in pixels of each step towards the destination position each tick. The default is 5, which means if the object is moving 20 pixels in a tick, it will move in four five-pixel steps.
Custom Movement conditions
Compare speedCompare the current speed of the movement, in pixels per second.
Horizontal and
Vertical compares to the
dx and
dy speeds respectively, and
Overall compares to the magnitude of the vector (
dx,
dy) (the overall movement speed).
Is movingTrue if either
dx or
dy are not zero. Invert to test if stopped.
On horizontal stepOn vertical stepTriggered for each step along an axis when
Stepping mode is either
Horizontal then vertical or
Vertical then horizontal. This can be used to accurately detect collisions with
Is overlapping.
On stepTriggered for each step when
Stepping mode is
Linear. This can be used to accurately detect collisions with
Is overlapping.
Custom Movement actions
Set enabledEnable or disable the behavior. If disabled, the behavior will not modify the object's position.
Rotate clockwiseRotate counter-clockwiseSetAdjust the angle of motion. This will calculate new values for
dx and
dy reflecting a new angle of motion with the same overall speed.
AccelerateAccelerate either the overall movement, or movement on a specific axis.
Accelerate toward angleAccelerate toward positionAccelerate the movement towards an angle or position.
Push out solidOnly valid when the behavior is currently overlapping an object with the
solid behavior. Automatically move the object until it is no longer overlapping the solid. This has no effect if the object is not currently overlapping a solid. The following techniques can be used:
Opposite angle reverses (or 'backtracks') the object from its current angle of motion until it is no longer overlapping.
Nearest moves the object in an eight-direction spiral out one pixel at a time until it is no longer overlapping. The aim is for the object to end up in the nearest free space, but since only eight directions are used it will be an approximation.
Up,
down,
left and
right moves the object along a specific axis until it is no longer overlapping.
Push out solid at angleOnly valid when the behavior is currently overlapping an object with the solid behavior. Move the object from its current position at a given angle until it is no longer overlapping the solid. This has no effect if the object is not currently overlapping a solid.
ReverseInverts the movement by flipping the signs of
dx and
dy.
Set speedSet the current speed in pixels per second either for the horizontal or vertical axes, or the overall movement speed. Setting horizontal or vertical speeds assigns
dx and
dy directly. Setting the overall speed calculates new values for
dx and
dy such that they reflect the new overall speed while keeping the same angle of motion.
StopA shortcut for setting both
dx and
dy to 0, stopping the movement.
Stop steppingOnly valid in
On step,
On horizontal step and
On vertical step. Stop the current stepping for this tick. The object can either go back to its old position (where it was at the start of the tick) or stay at its current position (possibly half way between its start and end positions).
Custom Movement expressions
dxdyReturn the movement's
dx and
dy values, which are the speed in pixels per second on each axis.
MovingAngleReturn the current angle of motion, in degrees, calculated as the angle of the vector (
dx,
dy).
SpeedReturn the current overall speed in pixels per second, calculated as the magnitude of the vector (
dx,
dy).