Set minimum distance to pathfind

Hello!

I’ve just started working with this program (it’s pretty great).
I’ve implemented into my game (a top down 2D RTS style game) and my characters path perfectly throughout my environment!
I have implemented a mouse option so that when I right click with a unit selected, the ‘target’ becomes an invisible object placed by the mouse, and the character moves there.
My issue is if I click directly behind my character they kinda moonwalk backwards or slide along the path.
I tried to implement the below solution, and it more or less worked

	distToTarget = Vector3.Distance(GetFeetPosition(), targetPosition);
	if(distToTarget>0.1f){
                    seeker.StartPath (GetFeetPosition (), targetPosition);
           }

however it got stuck in that position as the distToTarget parameter became always less than 0.1. I could pretty simply fix this by putting this if statement elsewhere, but I was wondering if there is a bit more of an elegant solution that exists that I just haven’t found yet. My solution also kinda sucks because you can’t move small distances (what I really want is for my characters to turn on a dime before they move.)

Thanks so much for any help!

Hi

First off you could try flipping the ‘slowWhenNotFacingTarget’ setting (if you are using the AIPath movement script at least, the AILerp movement script doesn’t have that option).

If having it enabled doesn’t produce the behavior that you want, I think you might be able to get it by tweaking the constants a bit.
In particular if you open the MovementUtilities.cs file and fine this line

// Lower the speed when the character's forward direction is not pointing towards the desired velocity
// 1 when velocity is in the same direction as forward
// 0.2 when they point in the opposite directions
float directionSpeedFactor = Mathf.Clamp(dot+0.707f, 0.2f, 1.0f);

You could change that 0.2 constant to e.g 0.01. Possibly also lower 0.707.