When increased Max Speed, my character goes insane

Hello, I am using AIPath and destination setter for my coffee concept game. I have a character and there are 5 tables in scene. So When im at bottom left, and click to top right, my character is going correctly with AStarPathfinding. But when increased maxSpeed, my character arrives there and draw a circle in that position and arrive there again. How can i fix that? I tried to use rigidbody2d. I almost tried everything but its’ not working. I need that because my users will be able to upgrade movement speed in time. So it gets a little absurd when increased movespeed. So is there anyway use exact movement so that my character doesn’t slow or act like real body. So that it goes exact second as i want?

This is my code,

	public class AIDestinationSetter : VersionedMonoBehaviour {
		/// <summary>The object that the AI should move to</summary>
		public Transform target;
		IAstarAI ai;
		private Transform _lastClickedPos;
		private bool _moving;

		void OnEnable () {
			ai = GetComponent<IAstarAI>();
			// Update the destination right before searching for a path as well.
			// This is enough in theory, but this script will also update the destination every
			// frame as the destination is used for debugging and may be used for other things by other
			// scripts as well. So it makes sense that it is up to date every frame.
			if (ai != null) ai.onSearchPath += Update;
		}

		void OnDisable () {
			if (ai != null) ai.onSearchPath -= Update;
		}

		/// <summary>Updates the AI's destination every frame</summary>
		void Update ()
		{
			MoveToTarget();
		}

		
		private void MoveToTarget()
		{
			RaycastHit2D rayHit = Physics2D.GetRayIntersection(Camera.main.ScreenPointToRay(Input.mousePosition));

			if (Input.GetMouseButtonDown(0) && rayHit.collider != null)
			{
				_lastClickedPos = rayHit.transform;
				var destinationPoint = _lastClickedPos.GetChild(0).gameObject;
				Debug.Log(destinationPoint.transform.position);

				if (ai != null)
				{
					ai.destination = destinationPoint.transform.position;
				}
			}
		}
	}
	
	
}

and my settings for aipath.
Screenshot_1

Hi

If the speed is too high you may get overshoot. The solution to this is to use sub-stepping: RichAI + Recast Graph falls though terrain
That post uses Time.timeScale as an indicator of how many steps to execute per frame, but you can similarly just make it execute for example 4 steps every frame at all times.

1 Like