top of page
Enemy wrap when facing a wall
Now let's put the necessary software to make the enemy rotate in the opposite direction when facing the wall.
1- First we will add the point line trace for object : you specify line From the beginning of the movement Character to Its end, and it will start right after the enemy move which means we will link it directly to an event. handlingmovement

1- First we will add the point line trace for object : you specify line From the beginning of the movement Character to Its end .
2- We will add a get actor location point and connect it with start.
3- We will add a point get actor forward vector and connect it with end
4- Add the multiply point that we will use to multiply the value we want the line to end at and connect it with get actor forward vector: It takes the value of the enemy’s movement from the front and its default value is (1). We multiply the value of get actor forward vector by the number we want the line to end at, for example (50).
We only want to make the character move right or left, i.e. in the X axis only.
5- So we have to click with the left mouse on the axes and then click split struct pin so that we can divide the character’s movement on all axes.
6- We add the point add, where we will add the forward vector value of the enemy get actor forward vector with the enemy location value get actor location .


object types : What type of objects do you want the line to track?
actors to ignore : What kind of things do you want the script to ignore?
What we need to do now is to identify those things, and to do that let's extract two points from them that identify the things.
7- We extract two points make array: which builds rows through which we can put all the things that we want the line to ignore or track.

We can show the line from the enemy by changing the draw debug type to for duration.

8- We determine the type of things that the line will track and in the end the enemy will turn around, which are:
Pawn: We have put a pawn in the upcoming lessons so that when we add new enemies, the current enemy will turn around when facing them (Information: All characters in Unreal have a collision property called pawn) .
worldDynamics: things that move in the world and may also be in the wall
worldcollision: so that the enemy turns around when facing a wall

9- We put things that he will ignore and in the end the enemy will not turn around when facing them, which is the character we will play with, and we can do this by:
Add the point get player character and connect it with make array so that the enemy ignores the character we are going to play.
Now we have to put the software that will do what happens after the line touches things.
10- Create a branch point from line trace for object return value
branch is a conditional statement, meaning it returns either true or false.
In case the enemy touches something ( stop once and then turn around ) and we can do that by:
11- Create a do once point : you do something only once.
12- Call get character movement : to get the enemy's movement data
13- We create the point set max walk speed from the enemy movement data get character movement
set max walk speed: We created this to make the enemy It stops When facing the wall
(0=set max walking speed)
Make the enemy stop for a certain period of time, then make him move at normal speed. To do this, we do the following:
14- We create the delay point : It delays the thing for a period of time in seconds.
We make the delay period (2 seconds)

15- Create a set max walk speed point again to make the enemy move at his normal speed.
(Basic)
But the question here is what is the character's basic speed?
We can find out by going to the character movement option and in the details list we write max walk speed.

16- Now we will convert the value of max walk speed to a new variable.
( promtes to variable ) We can change its value at any time, then click compile.
Let's make the speed value (200)

The problem is that when we go to the details of the max walk speed , we will find that it is still 600, so we have to make the movement speed 200 even at the beginning of the game, and we can do that either by changing the speed in the details or we can change it in the blueprint by doing the following:
17- When you start playing, change the enemy speed to 200.

18- Now we will convert the duration value in delay to a new variable.
( promtes to variable ) We can change its value at any time, then click compile.
Let's make the pause time value (2)

After the character returns to its normal speed, we will make it turn in the opposite direction, and we can do the following:
19- We will call the variable that we created previously get movedirection which holds the direction value
( scale value ) and its default value is ( 1 ).

20- We will create a multiply point by multiplying the default direction value by ( -1 ) to reverse the enemy’s direction and link it with the get movedirection value.
-1*1=1

21- We will call set movedirection so that the turning value changes when facing the wall and we will connect it after set max walk speed
22- To make this process repeat more than once, we must connect it with reset in do once .

23- Before we start playing, we change the order, making
event tick handling rotation handlingmovement

2- Enemy turns when approaching the edge
Now let's put the necessary software to make the enemy spin in the opposite direction if it faces the edge so that it does not fall.
First, we have to modify the background (wall). To modify it, we click on the wall.
We move to the place where we saved the file ( oakwoodsTilesmap ).

We click on the erase tool and erase the right part of the wall


We determine the points related to the turn when facing the wall and we put a comment .
After selecting , we press the letter C and name the comment detectwallandpawn.

1- We create a sequence point from the add movement input point.
sequence: Executes the code points in order 0 then 1.

2- We copy the code points in the comment ( detectwallandpawn ) that we created.
We connect it with sequence 1.

3- We create the subtract point and make the value of the Z axis (95) and connect it with get actor location and add at the end.

4- We create a branch point and in case of false (there is nothing under the character, so move to do once for the enemy to turn around)

5- We close the trace line ( none ) in the line trace designated for the wall, and we activate the trace plans designated for the edge.

We determine the points related to the turn when facing the edge and we put a comment. After the selection, we press the letter C and name the comment detectedge.
the explanation:
What we did is first we created a sequence that arranges the execution of the software actions.
We want the enemy to turn around when facing the edge after making sure there is no wall (sequence then (0
After making sure that there is no wall, we will move to (sequence then (1
The line trace will start from the enemy and end 95 units below (( Z=95 ) subtract )
50 in front of the enemy (( X=50 ) get actor forward vector )
If there is an edge, it means that the enemy must turn around, which is why we have connected (branch(false) with do once (there is nothing below the enemy at a distance of 95 units from the bottom and 50 from the front, turn around ( do once ))

bottom of page