#navmeshagent doesn't stop exactly at the proper stopping distance

1 messages · Page 1 of 1 (latest)

magic tide
#

hello! i have a navmeshagent currently set to follow the player with a stopping distance of 2f; however, i have noticed that it doesn't stop exactly once its 2f away from the player, it stops at 1.84f, i need it to stop exactly at 2f because i have code that runs once it reaches its stopping destination, can someone help me?

Debug.Log(
        "student remaining distance to reach you is " + navMeshAgent.remainingDistance
      );
Debug.Log(
        "but their stopping distance is " + navMeshAgent.stoppingDistance
);
edgy fulcrum
#

show more code

#

also what do you mean by exactly? do you mean the distance needs to be exactly 2? if you mean exactly 2 i don't recommend designing your code that way since comparing floats with == can be imprecise

magic tide
#

Sure!

navMeshAgent.destination = destination.position;
      navMeshAgent.speed = 1f;

      if (navMeshAgent.remainingDistance == 0 || navMeshAgent.remainingDistance == navMeshAgent.stoppingDistance) {
        animation.CrossFade(idleAnimation);
      } else {
        animation.CrossFade(walkingAnimation);
      }
      Debug.Log(
        "student remaining distance to reach you is " + navMeshAgent.remainingDistance
      );
      Debug.Log(
        "but their stopping distance is " + navMeshAgent.stoppingDistance
      );
magic tide
#

but it seems like when i set the stopping distance to 2f, and debug.log the value of remaining distance, it seems to stop at 1.84f according to
navMeshAgent.remainingDistance and not 2f

edgy fulcrum
magic tide
edgy fulcrum
#

very high?

#

the agent will stop at a distance anywhere from 0 to stoppingDistance away from the target

#

[]xy

reef merlinBOT
#

The XY problem is asking about your attempted solution rather than your actual problem. This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

  • You want to do X
  • You don't know how to do X, but think you can solve it if you can just about manage to do Y
  • You don't know how to do Y either, so you ask for help with Y
  • Others try to help you with Y, but are confused because Y seems like a strange problem to want to solve
  • After much interaction and wasted time, it finally becomes clear that you really want help with X, and that Y wasn't even a suitable solution for X
    Source: http://xyproblem.info/

Please include information about a broader picture along with any attempted solution, including solutions you have already ruled out and why.

edgy fulcrum
#

^^ give this a read. to me, it seems like a strange thing to want the agent to stop exactly at some distance from the target (Y). is there something you're actually trying to achieve with this (X)?

magic tide
#

let me rephrase, sorry i've never asked for help here before so i'm not 100% on how everything works around here.

so, currently, i have my agent moving towards my target(Y) (which is a moving target), i have it so that the agent would stop moving 2f away from the target(Y) using stoppingDistance, then i also use the value of stoppingDistance and check if its equal to remainingDistance, if it is, play the idle animation(X), otherwise, play the walking animation(X).

#

however, that doesn't work because as we were talking about, usually those values cannot be equal

edgy fulcrum
#

it seems like you just want to play the idle if the agent is stopped, is that true

magic tide
edgy fulcrum
#

okay lol. so in terms of the xy problem, X is detecting if the agent is stopped, and Y is detecting if the agent's remaining distance equals its stopping distance

#

btw im just using X and Y here to clarify how your problem relates to the xy problem. you don't need to use X or Y when asking a question here

#

so to summarize you actually just want to know how to detect if the agent is stopped

magic tide
magic tide
edgy fulcrum
#

okay i think you may be able to find some results online. try checking first, and if you don't find anything suitable, come back here

magic tide
#

found a solution that works perfectly, thank you so much for your help @edgy fulcrum (and thank you for actually making me look realize my mistake and google the correct thing myself)