let ai continously walk down a path - make AI go back to path if its outside

Hi!

€dit: the purple go back to path is actually what really bugs me.
Edit2: SOLVED: Mhousse1247 made this crazy function that seems to work

I have 2 things to ask about AI anvigation. The first one is about that i want to make ai pawns walk down paths. Right now they are just following a waypoint on the other side and theres lots of problems with a simple waypoint system like:

How do I make them go around corners eventhough pathing finds a shorter way?
How do I update to make them go to the next waypoint when they just passed a waypoint but did not exactly run over it (becasue thats the issue with waypoints in the first place that they are just a point)
And most important, how do I make them want to go only in one direction if i would use an area that is L shaped.

I am always thinking that id love to assign a “preferred direction” vector to a navigation area.


2nd problem:

Now if that would be sorted out Id have a bunch of AI pawns that are walking down a path. If they encounter an enemy they will chase down the enemy and fight it.

After fighting I want them to go back to the path.

Here a visual representation:

b278307f10a5e643a1963440c37264188379d847.jpeg

Sadly everytime I try to “move ai” to an actor or a component of an actor it will just walk to the actors world location.
Now theres quite some ways to do this that im aware of.

The problem I have is that therere could be about 50 of those ai pawns in the world and I do not want to make it too expensive on the performance.

check my ai project sample ( patrol , detect , chase , attack , kill,go back to path)

hello!

First off, thanks for your work helping the community. However your project does not really help me since you do use waypoints, just like I currently have. I hoped that I could replace this waypoint system with something that I have pictured above.

For example, if the AI pawn would get out of his path to chase down an enemy, with your system it would go back to its old waypoint. Now if this enemy would drag it around the map (in my graphic up or down) it would take the way back to its last waypoint whereas I want it to go back straight to the “path” and then walk down in the same direction it always has been.

I have everything working except for the purple “go back to path” AND hoped I could get something better than waypoints for the first thing wich is just walking down its path.

Now with the waypoint system in order to get back in to the path again I would need to do a “for each loop” on the array with waypoints and check the distance to each waypoint wich is kinda expensive. I tried different variations of “ai move to” on a volume that is the path, but it always defaults to the exact world location vector point that the volume is placed and never ever tries to actually get into the volume asap.

For walking down the path waypoints are allright, eventhough I hoped I could make a volume, assign a direction vector and let the ai pawns go with it.

If I understand your AI Pawn with patrol between 2 points?
Is that what you want to achieve?

correct. and my problem is the “when enemy killed”

right now i have lots of waypoints along the path and just use “get all actors of class” - “waypoint”] then [for each] and check wich one is the closest distance wich is quite expensive to use with many of them, and also it doesnt look neat, i hoped i could get a box instead and make it walk to the box (and not the box’ 0,0,0 point in local space)

the normal path works fine except i dont know whats the best way to tell the ai that it is currently in its normal path and should follow the waypoint at the end. (probably a box. but my fear is that this box over the whole map will overlap so many things, not just the pawn, that it will drag down the performance aswell)

oh and btw the game will end or it will die when it reaches the final point so it doesnt even need to patrol (wich works great anyways with a simple waypoint) it is currently patrolling, but can never return haha.

here is a quick solution

AI Character with a reference to the path

Path actor with:
Box Collision
Start & Target point
Get Closest Point Function

when the ai pawn is out the path , he gets the closest point and when overlaps the path trigger , he moves to the target point

Project Link

OH MY GOD, a “GET CLOSEST POINT” NODE!

I didnt update my project to 4.8 yet and there was no “closest point” node in 4.7

Thank you so much!

there is no " Get Closest Point" in 4.8 , it’s a function i made

oh man. I just noticed after I updated my project and set up everything.
my brain was already muddy from working on the ai over 13 hours now. and just the last thing was missing.

I now discovered the ingenious huge function and the construction script of the box. its ridiculous

f19a424347e9025bb20f4c2c2f21ecad34ce9503.jpeg

now i just hope my pc can run this