My RVO Controllers shake back and forth as they approach their targets when the targets also have RVO Controllers on them. Aron said this is because I’m setting to target to the middle of them. The RVO Controllers then jerk back and forth as they try to go around the controller while also trying to enter it.
How can I trim my path so that it’s X distance away from the center? I tried modifying p/path in OnPathComplete() in Seeker.cs with this but it didn’t work/
The trim is working correctly, but the path doesn’t seem to be updating correctly once I trim the final waypoint and remove the excessive ones after it. This is my OnPathComplete at the moment:
void OnPathComplete(Path p, bool runModifiers, bool sendCallbacks) {
if (p != null && p != path && sendCallbacks) {
return;
}
if (this == null || p == null || p != path)
return;
//////////
Debug.Log("vectorPath Count before trim - " + p.vectorPath.Count);
p.vectorPath = TrimPath(p.vectorPath, p.GetTotalLength(), 5f);
Debug.Log("vectorPath Count after trim - " + p.vectorPath.Count);
This is my TrimPath() code:
public List<Vector3> TrimPath(List<Vector3> pts, float lengthToEnd, float maxLength)
{
Debug.Log("NEW PATH -----------------------------------");
Debug.Log("Entering TrimPath()");
//For length testing
var totalLength = 0f;
var waypointLength = 0f;
Debug.Log("Start totallength is " + totalLength.ToString());
Debug.Log("Start waypointlength is " + waypointLength.ToString());
Debug.Log("Start waypoint count is " + pts.Count.ToString());
Debug.Log("Distance to final point is " + lengthToEnd.ToString());
//Add up each waypoint length and check if it's over our max length
for (int i = 0; i < pts.Count - 1; i++)
{
//Calcualte length of current waypoint section to the next. Ex, (1, 1, 1,) distance from (0, 0, 0) is (1, 1 ,1)
waypointLength = Vector3.Distance(pts[i], pts[i + 1]);
Debug.Log("i = " + i.ToString());
Debug.Log("Current totallength is " + totalLength.ToString());
Debug.Log("Current waypointlength is " + waypointLength.ToString());
Debug.Log("Current maxlength is " + maxLength.ToString());
//If the current waypointLength will put us over max length, recalculate it so that it doesn't
if (totalLength + waypointLength > maxLength)
{
Debug.Log("Total length + next waypoint length is greater than max length - " + (totalLength + waypointLength));
//Get the fraction of the size that we actually need it to be. Ex if max is 8, current total is 6, but next waypoint is 4 (giving us 10 instead of 8)...
//The fraction will be 0.5. Waypoint (4) needs to be cut in half then, in this case (6 + 2 = 8)
float fraction = (maxLength - totalLength) / waypointLength;
Debug.Log("Fraction is " + fraction);
//Cut wthe current point by the fraction above. Lerp because it's 3d
Debug.Log("Before Lerp " + pts[i + 1].ToString());
pts[i + 1] = Vector3.Lerp(pts[i], pts[i + 1], fraction);
Debug.Log("After Lerp " + pts[i + 1].ToString());
//If there are more points, remove them
Debug.Log("Removing the rest of the points since we are over max length");
Debug.Log("Count before RemoveRange " + pts.Count);
pts.RemoveRange(i + 2, pts.Count - (i + 2));
Debug.Log("Count after RemoveRange " + pts.Count);
//return;
}
totalLength = totalLength + waypointLength;
}
return pts;
}
Now I know that I’m modifying the right path because if I force it to null then my character doesn’t move. So why does trimming the ends off not correctly update the path?