Basic Follow AI

Hey all.

I have been trying for two weeks to get an AI tree that allows my bot to follow and attack my character. I have done three different tutorials to the T and for some reason my behavior tree does not work at all. At the moment I am beyond stuck and would love some help.

I am including my scene through drop box if anyone has the available time could they possibly check where I am going wrong.
Drop Box link

Tutorials used
https://docs.unrealengine.com/latest/INT/Gameplay/AI/BehaviorTreeQuickStart/1/index.htmlhttps://youtube.com/watch?v=VAAHKNoIg0w
Kind Regards
Twotents
Kelvin Grunig

Hello,

I’ve been having a look at your project and noticed a few things not quite right, but I’ve been able to get the AI guy to follow the player with the following changes:

First thing I did was to set your player collision to Pawn. I saw you had custom collision set but set it to Pawn for now just to get things working.

In the AgroCheck service you have a variable “Desired Object Location”, this is an array of object types that the sphere trace will look for (might be good to rename it “Desired Object Types”). You don’t have any types in the array so the sphere trace won’t hit anything. You need to select the variable and go to the Default Value panel, click the plus sign and choose Pawn from the popup menu. That adds the Pawn type to the array, you should see it say “1 elements”.

Next thing is the sphere trace node, set a radius, the tutorial shows 1500 but that’s a bit big for your scene, I set it to 500.

The next part caught me out all the time when I was learning Behaviour Trees! You need to make sure you have the Blackboard variables set correctly for each Service, Decorator and Task.

Select the AgroCheck service in the Behaviour Tree, in the Details panel set Target Location to Target Location and Target to Follow to PlayerToFollow.

CloseEnough Decorator, set Target to Follow to PlayerToFollow.

MoveTo task, set Target to Follow to PlayerToFollow.

BTT_MoveTO, set Target to Follow to PlayerToFollow.

etc…!

I think that was all the changes it took to make it work.

Hope that helps.

Cheers,

Mark

Hey Mark.

Thank you for taking the time to go over my project! I very carefully went over my blueprints again with your suggested changes, but unfortunately my bot still refuses to move.
I went back to the beginning with a blank slate and very very carefully followed the tutorial but I am starting to lose hope that I am going to get this behavior tree to work.

Here is another attempt

Kind Regards
Kelvin

Hi Kelvin,

Very close, don’t give up! The only remaining problem in your project is the collisions, it’s not finding the Player, everything else is setup fine.

The first change is in the service, connect up the Actors to Ignore that you currently have unconnected. Then for the End location you need to add a Z value to the location, you currently have it set to zero. It doesn’t look like the sphere trace works if the Start and End locations are the same.

If you watch the execution flow in your service you’ll see that it now goes into the loop body when your player moves into the detection area. The AI guy still isn’t moving though, that’s because the line trace isn’t hitting anything. There’s nothing set to block the Visibility channel.

There’s a couple of ways to fix this, the first is a bit of a hack but it’ll get things working quickly. Set the CapsuleComponent collision type to Custom for your Player and set the Visibility channel to Block. If you run the game now it should work.

A better way to do it would be to set the Mesh component in the Player to Custom collision and block Visibility. You’d then need to offset the start and end of the line trace so that it will hit the mesh, otherwise it’ll fire the ray between his feet and miss the mesh! Set the offset so that it will hit the chest area of the Player for example. Turning on the debug drawing on the trace node helps with this.

Lastly, just rotate your AI Mesh component -90 in Z so it faces the direction of the ArrowComponent. That’ll stop him running sideways :slight_smile:

Should work now I hope!

Cheers,

Mark

Omg thank you Mark. This is why i never got into coding lol I ALWAYS miss minor details because I get frustrated.

With this Tree working I can now add an attack function and actually get my assignment moving!

I really really appreciate all the help you’ve given.

By saying offset the line trace, do you mean the multi sphere or single line? How would I offset the capsule. Im assuming using the vector + vector node I just modify the X and the Y value so that it looks somewhere near my characters chest?

You’re welcome, glad you’ve got it working :slight_smile:

Ignore my suggestion to offset the single line trace, I was forgetting that it starts from the centre of the capsule, so it should work without it. I need to read up on the collision stuff in more detail myself, but I think you just need to make sure something on your player is set to block the channel chosen on the single line trace node.

Keep us updated with your progress!

Cheers,

Mark

Could anyone post their solution to a simple attack task blueprint? I know I have to execute an event that calls the bot looks for the player location and then spawn the projectile from the bot. Easy in words but getting it in practise is another story for me.