Using RVOQuadtree to find neighbors of Agent

Hi

Yes, this is possible.
If you are using the beta version then this is the relevant code:

var simulator = RVOSimulator.active.GetSimulator() as Pathfinding.RVO.SimulatorBurst;
var result = new NativeArray<int>(10, Allocator.Persistent);
var resultDistances = new NativeArray<float>(10, Allocator.Persistent);

var query = new RVOQuadtreeBurst.QuadtreeQuery {
    position = ...,
    speed = 0,
    timeHorizon = 0,
    agentRadius = float.PositiveInfinity,
    outputStartIndex = 0,
    maxCount = result.Length,
    result = result,
    resultDistances = resultDistances,
};
simulator.quadtree.QueryKNearest(query);

for (int i = 0; i < result.Length; i++) {
    int agentIndex = result[i];
    if (agentIndex == -1) break;
    var agentPosition = simulator.simulationData.position[agentIndex];
    Debug.DrawLine(query.position, agentPosition, Color.red);
}

It is kinda tricky to get from that back to the RVOController component and the associated GameObject though.

1 Like