RichAI For Smooth Consecutive Waypoints

I’m trying to build out a behavior for characters where they move in a circle around their target–keeping some radius/distance away from them at all times. The diagram below shows what I’m going for basically, the black points being the target waypoints on the blue circle and the red path being the path I expect the agent to follow ultimately.

image

I compute the waypoints easily enough on my own but when it comes time to feeding these destinations to my RichAI agents on my Recast graph I seem to hit up against some path computation timing issues.

This is mentioned in the docs in the examples of creating your own movement scripts. Starting to compute the next path when nearing your current destination otherwise the agent may stand still for a frame or two while the next path computes. That makes sense generally, but writing a completely new movement script seems overkill for this. Not to mention this would sidestep the advantages of the RichAI script such as the funnel simplification.

I have tried using a custom p ath anyway. Trying to use a custom path with the RichAI by having the seeker precompute the journey to the next waypoint causes an error to pop up due to the RichAI agent listening to the seeker’s path compute complete event. Even disabling computePath on RichAI doesn’t stop this error however.

Apologies for the noise! Bumping this for any further insight.

This is suprisingly easy with the FollowerEntity component.
The benefit of using that component is that it will repair its path every frame, even without a full path recalculation. So you can get very smooth movement without having to crank up the path recalculation rate.
It can be used with other movement scripts as well, but they may not be as responsive.

output

class MoveInCircle: MonoBehaviour {
	public Transform target;
	public float radius = 5;
	public float offset = 2;

	void Update () {
		var ai = GetComponent<IAstarAI>();
		var normal = (ai.position - target.position).normalized;
		var tangent = Vector3.Cross(normal, Vector3.up);

		ai.destination = target.position + normal * radius + tangent * offset;
	}
}
1 Like