How to make AI walk backwards

Hey guy´s and girls. This is my first post here so thumbs up for that :smiley:

I´m currently developing a game with a friend of mine, im working on the AI atm and got stuck a bit. I´m trying to find a way to make the AI moveToLocation and still watch me. I have my self set as focus for the AI but if he is running in the opposite direction of me he just looks to his 90 or -90 and runs real wierd. Is it possible to make him move backwards if he cant keep me in his aim when he goes forward. :smiley:

Thanks in advance
Best regards
Jóhann Ingi

Hey,

could you provide some more information?

Shall the AI always focusing you?

Assuming He watches and looks with his head.

How do you define the 90, -90? Do you have any Field of Vision for the AI? If yes,
why not telling it when the Player Location isnt inside this field disable focus → return to look like a normal guy → move backward (maybe reverse the walk animation) → Check if the Player is in fieldrange again, set focus back.

if not or If i got you wrong, please tell me what and when your AI should do something :wink:

kind regards

Hey there and thanks for a quick response :slight_smile:

25414-combat.png

What is currently happening is the following. When the enemy is in combat with me and is moving away from me like on this picture, running to the cover. I am positioned in -170 degrees from the direction he is running in. He can only turn to -90 degrees.

What I would like to have is when my postition is not inside the 90 to -90 arc from is moveing direction. He instead walks backwards so he can look at me and shoot on the way.

I´m not really sure on where I should implement this. Im currently working with the 1st person shooter template and the enemy i´m using at the moment is Owen from the example content. For the movement I use moveToLocation and for him to aim at me im using set Focus. Would be super nice if you could point me in the direction on how to implement this.

Best regards
Jóhann Ingi

hmmm ok…

if i get you right you are looking for the angle between you and him, regarding the viewdirections of both.

You can get this angle and check if its within the angle range you wish.

To get this angle you need the dotproduct (i think there should be a function in blueprints), this returns a scalar you can convert via the arcos function into an angle or a radiant.

I would recommend to normalize both vectors before you create the dotproduct. Dunno if there is a function for normalizing but i assume since epic is a high-professional team :), there is because its one of the basic math functions if you are having vector and other multidimensional math classes :wink:

maybe that helps

best regards

You have to set the focus. By default the focus is set to be in front of them, but it you set the focus to the player for example, and then get them to walk away from the player, they will be walking backwards. basically the focus is where they face.

for example:

25423-capture.png

1 Like

Set Focus does the trick. Thanks!