#Need help with getting a Navmesh Character to Sit down!

1 messages · Page 1 of 1 (latest)

oak coral
#

So, I am trying to get my character model which is a Navmesh agent to sit down on a stool. It's not working at all. The character refuses to sit. As you can see in the image, the sitting point of the Stool is placed a bit over the stool's collider. And the Character also has a box collider (The Box which is shown in the picture where the character is selected) which I use for interacting with the character and the Cylinder in the same image is basically its Navmesh.

So, I am kinda really lost on how to get the character to sit on the stool!! I would appreciate any help.

#

This is the code snippet where the sitting is supposed to happen:

yield return new WaitUntil(() => isOrderTaken);

currentState = CustomerState.GoingToTable;
if (activeAnimator != null)
    activeAnimator.UpdateAnimations(false, true);

Transform chair = FindFreeTable();
if (chair != null)
{
    agent.SetDestination(chair.position);
    yield return StartCoroutine(HasReachedDestination());

    agent.isStopped = true;
    agent.ResetPath();

    transform.position = reservedChair.chairTransform.position;
    transform.rotation = reservedChair.chairTransform.rotation;

    agent.updatePosition = false;
    agent.updateRotation = false;
  
    if (activeAnimator != null)
    {
        activeAnimator.UpdateAnimations(true, false);
    }

    Vector3 lookDir = reservedTable.transform.position - transform.position;
    lookDir.y = 0;
    if (lookDir != Vector3.zero)
        transform.rotation = Quaternion.LookRotation(lookDir);
}

currentState = CustomerState.WaitingForFood;
Debug.Log($"{gameObject.name} is waiting for food.");
if (activeAnimator != null)
    activeAnimator.UpdateAnimations(true, false);

The chair.position is basically the sitting position. And FindFreeTable function returns the sitting position of a chair that's free.

#

This is the UpdateAnimations function if you're wondering, it's a placeholder for now. If both are false, it'll go to idle animation.

public void UpdateAnimations(bool sitting, bool walking)
{
    isSitting = sitting;
    animator.SetBool("isSitting", isSitting);

    isWalking = walking;
    animator.SetBool("isWalking", isWalking);
}