I am trying to run pathfinding using some code from the lightweight RVO example on top of basic recast graph pathfinding. It is not using any modifiers, and there isn’t really any problem with the path itself, but the agent is jittering quite a bit as you can see in the footage:
For the movement, I am using a modified seeker script which calculates the movements and passes the target to the RVO simulator:
var vectorPath = vectorPaths.ToNativeArray(Allocator.Temp);
if (vectorPath != null && vectorPath.Length != 0)
{
while ((math.lengthsq(To2DIn3D(translation.Value - vectorPath[pathfinder.wp].Value)) < agentData.moveNextDistance * agentData.moveNextDistance &&
pathfinder.wp != vectorPath.Length - 1) || pathfinder.wp == 0)
{
pathfinder.wp++;
}
// Current path segment goes from vectorPath[wp-1] to vectorPath[wp]
// We want to find the point on that segment that is 'moveNextDist' from our current position.
// This can be visualized as finding the intersection of a circle with radius 'moveNextDist'
// centered at our current position with that segment.
var p1 = vectorPath[pathfinder.wp - 1].Value;
var p2 = vectorPath[pathfinder.wp].Value;
// Calculate the intersection with the circle. This involves some math.
float3 t = VectorMath.LineCircleIntersectionFactor(To2DIn3D(translation.Value), To2DIn3D(p1), To2DIn3D(p2), agentData.moveNextDistance);
// Clamp to a point on the segment
t = math.clamp(t, 0, 1);
float3 waypoint = math.lerp(p1, p2, t);
// Calculate distance to the end of the path
pathfinder.remainingDistance = math.length(To2DIn3D(waypoint - translation.Value)) + math.length(To2DIn3D(waypoint - p2));
for (int i = pathfinder.wp; i < vectorPath.Length - 1; i++) pathfinder.remainingDistance +=
math.length(To2DIn3D(vectorPath[i + 1].Value - vectorPath[i].Value));
// Set the target to a point in the direction of the current waypoint at a distance
// equal to the remaining distance along the path. Since the rvo agent assumes that
// it should stop when it reaches the target point, this will produce good avoidance
// behavior near the end of the path. When not close to the end point it will act just
// as being commanded to move in a particular direction, not toward a particular point
float3 rvoTarget = math.normalize(waypoint - translation.Value) * pathfinder.remainingDistance + translation.Value;
// When within [slowdownDistance] units from the target, use a progressively lower speed
desiredSpeed = math.clamp(pathfinder.remainingDistance / agentData.slowdownDistance, 0, 1) * agentData.maxSpeed;
// Set target in rvo controller
data.SetTarget(agentData.rvoSimulationIndex, rvoTarget, desiredSpeed, agentData.maxSpeed);
When there are multiple units it does it less frequently, which leads me to assume it might be something to do with how the local avoidance.
I haven’t been able to figure out what is happening and thought I would check to see if this has possibly been an issue you have experienced. Any idea what might be causing this behavior?