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?