예제 #1
0
    private void Follow()
    {
        if (shouldFollow)
        {
            Vector3 ownerPosition = owner.transform.position;
            Vector3 ownerForward  = owner.transform.forward;
            switch (subState)
            {
            case DogSubState.FollowPath:
            {
                if ((latestTargetPos - ownerPosition).magnitude >= repathDistance ||
                    Vector3.Angle(latestTargetFront, ownerForward) >= repathAngle)
                {
                    Repath(followOffset);
                }

                else if (!navAgent.pathPending && navAgent.remainingDistance <= followDistanceReached)
                {
                    animator.PlayFullBodyState(States.AnimalFullBody.Idle);
                    latestTargetFront = ownerForward;
                    latestTargetPos   = ownerPosition;
                    startLookAtTime   = Time.time + lookAtDelay;
                    subState          = DogSubState.FollowWait;
                }

                if (Time.time >= startLookAtTime)
                {
                    subState = DogSubState.FollowLookAt;
                }
                break;
            }

            case DogSubState.FollowWait:
            {
                if (Time.time >= startLookAtTime)
                {
                    subState = DogSubState.FollowLookAt;
                }

                if ((transform.position - ownerPosition).magnitude >= lookAtExitDistance ||
                    Vector3.Angle(latestTargetFront, ownerForward) >= lookAtExitAngle)
                {
                    startLookAtTime = float.MaxValue;
                    Repath(followOffset);
                    animator.PlayWalk();
                    subState = DogSubState.FollowPath;
                }

                break;
            }

            case DogSubState.FollowLookAt:
            {
                Vector3 targetDir = owner.transform.position - transform.position;
                LookAtTarget(targetDir);

                if ((transform.position - ownerPosition).magnitude >= lookAtExitDistance ||
                    Vector3.Angle(latestTargetFront, ownerForward) >= lookAtExitAngle)
                {
                    startLookAtTime = float.MaxValue;
                    Repath(followOffset);
                    animator.PlayWalk();
                    subState = DogSubState.FollowPath;
                }
                break;
            }
            }
        }
        else
        {
            OnFollowExit();
            OnPatrolEnter();
        }
    }
예제 #2
0
 public void Eating()
 {
     m_AnimatorDriverAnimal.PlayFullBodyState(States.AnimalFullBody.Eat);
     isConsuming = true;
 }