Weird Behavior, richAI.remainingDistance over shoots destination?

i am getting very weird results over here, basically, the richAI remaining distance, when we are “near” the target, keeps fiddiling and overshooting?

Here is the code

	void Update()
	{
		Debug.Log("remaining dist " + richAI.remainingDistance + " : end reached dist : " + richAI.endReachedDistance);

		Ray ray = main.ScreenPointToRay(Input.mousePosition);
		if(!Physics.Raycast(ray,out RaycastHit h,castDist,floorMask))
			return;
		if(!player.GetButton("MoveUnit"))
			return;
		richAI.destination = h.point;
		pointerEffect.Activate(h.point);
	}

Here is a clip

i am using the latest beta, and unity 2022.3.7f1, and on windows 11 home

here are four readings (console messages)
I have noticed that, this behavior starts showing up, the moment, the remaining distance, becomes less than end reached distance for the first time.

remaining dist 0.4829559 : end reached dist : 0.525
UnityEngine.Debug:Log (object)
PA_Player:Update () (at Assets/00_Game/Prototype_A/PA_Player.cs:28)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

remaining dist 0.9275871 : end reached dist : 0.525
UnityEngine.Debug:Log (object)
PA_Player:Update () (at Assets/00_Game/Prototype_A/PA_Player.cs:28)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

remaining dist 0.4077984 : end reached dist : 0.525
UnityEngine.Debug:Log (object)
PA_Player:Update () (at Assets/00_Game/Prototype_A/PA_Player.cs:28)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

remaining dist 0.8107614 : end reached dist : 0.525
UnityEngine.Debug:Log (object)
PA_Player:Update () (at Assets/00_Game/Prototype_A/PA_Player.cs:28)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Note:
i noticed this issue first, when i was trying to animate my character, basically, he was jittery towards the end.
this was my code
where my animator, accepts value from 0 to 1
animator.SetFloat("MovementTypeF", richAI.velocity.magnitude / richAI.maxSpeed);

so upon debugging, i noticed a weird difference in ai.velocity, and in turn, i checked the ai.remainingDistance and it was acting weird as well.

so instead of that i am now using the following code to animate my character

float dist = Vector3.Distance(richAI.position,richAI.endOfPath);
	    float locomotionSpeed = 1;
	    if(dist<=richAI.endReachedDistance)
	    	locomotionSpeed = dist/richAI.endReachedDistance;
	    
	        animator.SetFloat("MovementTypeF", locomotionSpeed);

But Yeah, i expected that remaining distance, would continiously get less, and less as we approach the target same for velocity?

Hi

Yeah, other users have reported similar issues with the remaining distance. I’ll try to look into it. Thanks for reporting.

Hey
Thank you for your hard work
something i wanted to note, i actually got it working properly last night

so, my end reached distance was 0.525 and my slowdown time was 0.6,
reducing endReachedDistance to 0.08 fixed the issue somehow.

it feels to me that the “slowDownTime” and the “endReachedDistance” appear to fight each other, when the endReachedDistance is large, and when the slowDownTime is large for some reason.

also, i checked the demo of the spider bot, i honestly, couldn’t make sense why a small value for stoppingDistance is used by default/recommended value, feels like it wo uld break in many occasions having it that low, but for now, its working fine?

if you could include in the “toolTips” what are the recommended values comparatively to each other, that’d be great :smiley:

thanks for your hard work

1 Like