I am using AIPath for movement and have the following method for stopping movement when needed:
public void StopMovement()
{
aiPath.isStopped = true;
aiPath.canSearch = false;
}
However, sometimes I need to stop the movement immediately (without being affected from smoothing /lerp) by making sure the velocity gets to zero right away. For instance, when the agent goes to a door and interacts with it, the door gives the instruction to face the door but because the velocity from the movement keeps on updating for some time, it does not reflect on the animation. So I need to get the velocity to zero right away before the interaction with the door begins (so the agent can face the door when the instruction comes).
I tried the following two solutions I could think of but none worked. Can you please help?
Tried Solution 1
public void StopMovement(bool stopImmediately = false)
{
if(stopImmediately) aiPath.maxAcceleration = 10000;
aiPath.isStopped = true;
aiPath.canSearch = false;
SetMovementState(CharacterMovementState.Idle);
StartCoroutine(StopMovementCo());
}
IEnumerator StopMovementCo()
{
yield return new WaitForSeconds(1f);
aiPath.maxAcceleration = -2.5f;
}
Tried Solution 2
public void StopMovement(bool stopImmediately = false)
{
aiPath.isStopped = true;
aiPath.canSearch = false;
if(stopImmediately)
{
aiPath.Move(Vector3.one); // I also tried Vector3.zero
aiPath.FinalizeMovement(aiPath.position, aiPath.rotation);
}
}