Construct 2 – 8 Direction Behavior

Now that we have a basic understanding of
what a Behavior is in Construct 2, and we know how to add a new Behavior to an object,
we can start taking a look at the individual behaviors themselves. The first one that I’d like to discuss,
is the 8 Direction Behavior. The 8 Direction Behavior allows an object
to be moved in 8 directions, up, down, left, right, and diagonally. This can be useful in an RPG, or a Space Shooter,
and many other types of games, once you know how to customize the Behavior to perform how
you want. I have a layout setup here, with this player
object. Right now, the player does nothing. It has no behaviors, so it’s basically stationary. Let’s go ahead and add the 8 Direction Behavior
to the player object. Select the player, and click on Behaviors. Click Add New, scroll down to Movements, and
select 8 Direction. If I preview the layout, you can see how the
8 Direction Behavior affects the player object with the default settings. By default, the 8 Direction Behavior is controlled
with the arrow keys. If I press the Right arrow, the player starts
moving to the right. If I press the Up arrow, the player object
rotates to face up, and begins moving upward. If I push the Left arrow, the player rotates
and moves left. The Down arrow, he rotates and travels down. If I hold the Right arrow and the Up arrow,
he moves diagonally, and he can go in each direction diagonally. So, by just adding the 8 Direction Behavior,
we already have useable controls for our player object. Whatever object you apply the 8 Direction
Behavior to, can be moved around the screen using the arrow keys. By default, the object smoothly rotates around
360 degrees as you turn. We can alter the way this Behavior affects
the object, by changing the parameters of the Behavior. With the player object selected, you can see
the parameters of the 8 Direction Behavior, in the Behaviors tab. Let’s go through each of them, starting
from the bottom. The last parameter on this list, is Initial
State. Initial State determines whether the Behavior
is enabled or disabled at the start of the layout. It’s set to Enabled by default, but if I
set it to Disabled, and I preview the layout, when I press the arrow keys, nothing happens,
because the 8 Direction Behavior is Disabled. We’ll go into events in depth in the future,
but throughout the series, I’ll show you some examples using events, so that you can
see the capabilities of Construct 2. If I switch to the event sheet, I can Add
a New Event. I’ll select System, and then On Start of
Layout. So, this event will occur when you start this
layout. I’ll add an action, so when the start of
the layout occurs, we will wait for 2 seconds. Now, if I add another action after this one,
Wait for 2 seconds, it won't occur until 2 seconds has passed. The system will wait for 2 seconds, and then
continue on with the actions. At that point, I’ll Enable the 8 Direction
Behavior. Now, if I preview the layout, and I press
the arrow keys, the player is stuck. After 2 seconds, the controls are enabled. Easy enough. Let’s go ahead and delete this event, and
set the Initial State back to Enabled. Above that, we have Default Controls. Default Controls has two options, yes, and
no. It’s set to yes by default, which means
that the arrow keys are enabled to control the object’s movement. But, sometimes you may want to use the WASD
keys instead of the arrow keys. Or you may want to create a completely unique
control scheme. By setting Default Controls to no, the arrow
keys will be Disabled, and you’ll have to redefine their replacements. Setting up a custom control scheme is something
we'll look into in the future, but just so you are aware of the possibilities, you can
trigger an event when a key is pressed, and then use the Simulate Control action, to define
which keys you want to control the movement. The next parameter we have is Set Angle. Set Angle determines how the 8 Direction Behavior
changes the angle of the object during movement, or if it changes the angle at all. The default is 360 degrees, or Smooth. This will smoothly rotate the sprite 360 degrees
around the sprite’s origin point. When I change direction, the sprite smoothly
rotates to face in the direction I’m moving. Set Angle has 3 other options, No, 90 degree
intervals and 45 degree intervals. If you set Set Angle to no, then Construct
wont change the angle of the sprite at all. So, the player starts out facing forward,
but if I move him up, or even backwards, he still remains facing forward. This is similar to a space shooter, where
the player is facing forward at all times, but may move in all 8 directions without changing
angle. 90 degree intervals and 45 degrees intervals
are both very similar. When either of these are selected, when the
player starts travelling in a new direction, the angle will be adjusted in either 45 degree
increments, or 90 degree increments. With it set to 90 degree intervals, we start
out facing forward, but if I go up, the player rotates 90 degrees, and faces directly up. It doesn’t smoothly transition to the new
angle, like the 360 degree option. 45 degrees is similar, but if you select it,
the player can actually face in all 8 directions. Just like with the 90 degree option, we can
face right, up, left, and down. But, now we can also face up right, up left,
down left and down right. For our example here, I’m going to set Set
Angle to no. The next parameter we have is Directions. Directions determines which directions the
behavior will allow the object to travel in. The default is 8 directions, meaning you can
travel up, down, right and left, as well as diagonally in any direction, up right, down
right, down left or up left. We can change it to Up and Down, Left and
Right or 4 Direction. Up and Down, and Left and Right are easy enough
to understand. Up and Down limits the movement to just Up
and Down, while Left and Right limits the movement to Left and Right. 4 Direction, however, can be used to limit
direction to up, down, left and right, restricting movement diagonally. The top 3 parameters work together, to control
the speed of movement. We have Max Speed, Acceleration, and Deceleration. Each of these values are in pixels per second. Max Speed is the highest speed, in pixels
per second, that the object can travel in any direction. Currently, it’s set to 200, which means
that if I get this object moving as fast as it can go, it will be moving across the layout
at 200 pixels per second. Acceleration is how fast the object speeds
up, in pixels per second. I’ll set it to 50 for this example. So, we start out stationary, moving 0 pixels
per second. When I press the right arrow, the object travels
to the right, starting out at 50 pixels per second. After one second elapses, it is travelling
at 100 pixels per second. It takes 4 seconds for this object to get
up to the full speed of 200 pixels per second. Last, is Deceleration. This is how fast the object slows down once
the arrow key is released. I’ll set the Acceleration to 200, which
means the object will reach it’s max speed as soon as you press the key, and the Deceleration
to 50, which means it takes 4 seconds for the object to come to a halt after you release
the arrow key. When I press an arrow, the player will be
travelling at 200 pixels per second. When I release the arrow key, the player begins
to slow down, subtracting 50 from the speed every second. So, there you go…that is the 8 Direction
Behavior in Construct 2. Now, you should be able to use this behavior,
and understand what altering each of the parameters will do. 8 Direction is one of the most commonly used
Behaviors, because it’s suitable for such a wide variety of games. Thanks for watching! If you’ve found this content helpful, please
consider supporting me on Patreon. Comment, like and share this video and subscribe
for more tutorials. See you next time!

7 thoughts on “Construct 2 – 8 Direction Behavior

  1. Hi, how can we use 8direction for onTouch left, right, up, down buttons. I tried it, but the character just disappear and appear on the area that is touched instead of gradually moving in a normal speed.

  2. I had spent a lot of time in Construct 2 for a few contract jobs, but I took a break from it for school. These tutorials have really helped me get back into the swing of things quickly. Nicely done.

Leave a Reply

Your email address will not be published. Required fields are marked *