Making path "correction" as soon as posible

Hi everyone,
I am building a system in order to make the level fine the level difficulty.
To do this, I integrated the AI ​​PathFinding system to connect from obstacles automatically, so that I can run a lot of experiments that resemble the running of a real person.

The problem is the “way” I get the shortest path… it avoids the obstacle only as soon as it getting close to it, and I actually want the “correction” to be immediate. Simply the problem in the current implementation is that the plane is not not fast enough to avoid in time and then collides with almost all obstacles instead of dodging.

Ideas how to change the calculation of the route to what I want it to be?

Current implementation:

The one I want:

Hi

I don’t think this is possible I’m afraid. You can try experimenting with the A* Inspector -> Settings -> Heuristic settings, but I don’t think you can get a solution that works in all cases.
I’d recommend adding a bigger margin around your obstacles so that the agent has time to turn.

Can I somehow tweak the algorithm that find the path?
To give a close straight line more weight/penalty than diagonal line? so that the algo will prefer chossing closer diagonal lines and it will give me this solution

That will not work in general. You will just have the same issue if you rotate the problem 45 degrees.

If you excuse my 5-second drawing:

1 Like

You are right… :confused:

My obstacle going in a straight line, (right to left)
When my player can move only in the Y-axle up and down

So in this case it will go straight to the obstacle

Well, the problem is still that I don’t think the desired effect can even be accomplished by changing direction weights. You make diagonals have a lower cost, sure. But it will still pick the same path as it did before because it has the same cost. The path is still composed of a fixed number of diagonals and a fixed number of straight connections. The cost will be the same for the two paths regardless of how you weight the diagonals.

An alternative that might work for you is to simply make the colliders for the obstacles wider towards the player. That will force it to avoid them with a bigger margin.

Regarding number 2, the problem with this approuch is that the collider is affecting other mechanism, so I’ll need to investigate how can I add one specific for this purpose, and not sure what will happen if the user will touch it before the actuall object arrived… how will the algorithm will behave.

What I meant is give a mix scoring.
e.g. some kind of scoring table:
STEP-NUMBER |||. DIAGONAL ||| STRIGHT LINE
1 1 1
2 2 1
3 3 1
4 4 1

So the total sum of taking diagonal route first will be lower…

Such a table can unfortunately not be done right now. At least not easily :confused:

I’ll give it a shot :slight_smile:
Can you refer me to the relevant class that you think might be relevant for such a change?

That would be the GridNode.Open method. You can find the cost of the path up to that node using the pathNode.G field (the cost is usually 1000 to traverse 1 world unit).

OK Cool, thanks
I’ll give it a try

1 Like