Path Points Cutting Corners [SOLVED]

Hi all,
I want to write a function that changes the points on a path obtained using the navigationmesh in such a way that it does not cut corners too much.
Meaning: instead of using all the “default generated” points, I would like to use a parameter to offset points that are close to corners, dependent on the radius of the agent.

Context:
I’m working on a movement AI for vehicles. I use the following code to obtain all path points to a particular destination, saving them in a global variable:
PointsFromPath
I’m using a behaviour tree that loops through the points stored in the gv. Before moving the vehicle to the next point, the vehicle is turned s.t. its front is aligned with the next location.
Turing near corners on the path is a problem with this because the points are too close to the corners.

What I have tried:
in the BT for moving I use a parallel with raycasts checking if there is space to turn, if not the vehicle repositions and the path is recalculated using the function in the snippet above. This is hard to get to work correctly and hence I’m looking for a way to enhance the existing c++ function, s.t. the points are better suited for turning.
I have also tried to change the radius of the agent hoping the corner-points would get better offset:

Query.SetNavAgentProperties(NavAgent);

Unfortunately, this does not seem to work.

Any help is greatly appreciated. also, if you have an alternative suggestion for fixing this problem feel free to let me know.
Best.

PS: I’m okay with the solution being relatively expensive, I prefer a well working expensive solution over a moderately working cheap one. I do not expect to have too many vehicles in my game.

I had a similar problem and found out that FNavMeshPath already has OffsetFromCorners function, but I have not seen it used anywhere in the engine where I could access it. So what I ended up doing was writing my own static FindPathToLocation function which uses this function.

Here’s how it looks:


(Ignore the red squiggles… Intellisense :roll_eyes:)

Here’s pastebin:

(It contains both header and cpp implementation, and you will have to change the class identifier to yours if you want to use it)

So far it’s been working flawlessly.

1 Like