I have debugged quite a lot of what’s happening and it’s quite weird.
I have a “charge” skill where I get the target’s position and then I add my vector forward to ram through him. So far so good.
m_Data.Seeker.StartPath( p_Caster.CharObj.transform.position, targetPosition, Callback );
private void Callback( Path p )
{
if( p.error )
{
Debug.LogWarning( p.errorLog );
CalculatePathAsync();
}
else
{
for( int i = 0; i < p.path.Count; i++ )
{
Debug.Log( m_Cube );
m_Cube = GameObject.CreatePrimitive( PrimitiveType.Cube );
Destroy( m_Cube.GetComponent<Collider>() );
m_Cube.GetComponent<Renderer>().material.color = Color.red;
m_Cube.transform.position = ( Vector3 ) p.path[ i ].position;
}
m_Agent.isStopped = false;
}
}
The “debug” Cubes get created as should and have the correct positions.
Now where the problems happens:
On my Update method I have:
var buffer = new List<Vector3>();
m_Agent.GetRemainingPath(buffer, out bool stale);
for (int i = 0; i < buffer.Count - 1; i++) {
Debug.DrawLine(buffer[i], buffer[i+1], Color.red);
}
Debug.Log( stale );
On the first Update after the callback, I get the line showing up correctly, with that I mean it’s going through all cubes that were created in a straight line . stale is always false yet after a few seconds the end vector becomes different ( even though buffer.Count is the same ) and it seems like the path gets trimmed halfway and that’s where the agent actually stops.
Frame before "trim": (20.2, 0.0, -25.8) (-4.2, 0.0, 9.0)
Frame after "trim": (20.2, 0.0, -25.8) (4.4, 0.1, -3.2)
Buffer count is at both times 2.
I’ve noticed in my debug:
Debug.Log( m_Agent.remainingDistance + " " + m_Agent.endReachedDistance + " " + m_Agent.reachedEndOfPath );
remainingDistance jumps from 40 to 30 at some point even though all the other distances get reduces uniformingly by 1-2 each time.
For this test Im running 1 agent and I have turned his RVO off even though it doesn’t make any difference. Everything is happening without any obstacles or any other issues around the agent.
Could something automatic be going on from the engine? I am not changing anything else in my code.
EDIT: Could it be that the algorithm sees that the player is in the middle and that the path will get blocked so it trims it there? Is there a way to turn that off or should I just switch layers?