Help using box traces?

Hi! I’ve been trying to grasp my head around using box traces, but I can’t seem to figure out how to use them properly… (keep in mind it’s a 2D game, so Y is ignored)
Here’s the box trace:


I’m working on the AI for my game, and what I want the box trace to do is essentially “scan” for a nearby player and then walk towards him. I got the second part covered, but I can’t, for the love of me figure it out…

As you can see in the picture above, I have it set so that every tick it runs a box trace. If I leave it like how it is in the picture, everything basically works, with one exception: if the player jumps it gets out of the reach of the box trace, and the enemy doesn’t know what to do. Makes sense, right? Because in the picture when I add to the player’s location I don’t add anything in the Z.

Here’s what it looks like “fixed”:


This is where the problem lies. As soon as I have it add to the Z, it screws everything up. It doesn’t work, at all. Sometimes when I’m jumping and moving around the enemy he’ll budge a little bit but that’s about it. I have no idea what’s causing this.

Here’s how I think box traces work:


That’s what I thought I was doing in the second image, but I guess it didn’t work…

Please help! I really appreciate it.

Here’s your reward:

Do the scan from the location of your AI to the location of your Player.

And if you want your AI to walk to your Player when the player character is within a certain range, a better way would be to just check the distance between them and move your AI if the player is in range. (In order to get the distance between them: subtract the location vector of your AI from that of the player and use a vector length node.)

Sorry, what exactly do you mean by doing the scan from the location of my AI to the location of my player?

As for the second part, I was already doing that, thanks :slight_smile:

Thank you for your reply!

Lol… I went around it in a weird way. I made a trigger/collision box around my enemy which is essentially the box trace that I was trying to accomplish. I made it so that on component overlap begin sets a boolean variable called “IsFollowing” to true, and on component overlap end sets it to false. Then every tick it branches out, and if it is true, it does the following code. Probably not the best way to go around it, but it works. Let me know if you think something of this :stuck_out_tongue: