private void MaintainProxemicDistance()
{
float distanceToUser = Vector3.Distance(transform.position, user.transform.position);
if (distanceToUser < minDistance || distanceToUser > maxDistance)
{
Vector3 directionToUser = (user.transform.position - transform.position).normalized;
if (distanceToUser < minDistance)
{
targetPosition = user.transform.position - directionToUser * averageDistance;
navMeshAgent.SetDestination(targetPosition);
SetAnimationState(false, false, false, true); // Walking backward
}
else if (distanceToUser > maxDistance)
{
targetPosition = user.transform.position - directionToUser * averageDistance;
navMeshAgent.SetDestination(targetPosition);
SetAnimationState(true, false, false, false); // Walking forward
}
}
else
{
navMeshAgent.ResetPath();
SetAnimationState(false, false, false, false); // Idle
StartCoroutine(TurnToFaceUserCoroutine());
}