Exemple #1
0
    void patrol()
    {
        if (Vector3.Distance(transform.position, home) < 2)
        {
            if (stuckBlocker <= 0)
            {
                if (IsStuck(newPosition, oldPosition, oldPosition2))
                {
                    posTimer = 0;
                    posTimer = 5;
                    if (TestDebug)
                    {
                        print("resetting path");
                    }
                    agent.ResetPath();
                    previous2   = previous;
                    previous    = currentNode;
                    currentNode = null;
                    State       = InuState.Flee;
                    return;
                }
            }
        }
        seen = false;
        seen = SeeObject(PlayerObject, LevelMask, home);
        if (seen)
        {
            awake = true;
            State = InuState.Chase;
            return;
        }

        foundFootprint = SeeFootprint(allNodes, LevelMask, home);

        if (foundFootprint != null)
        {
            nextFootprint = foundFootprint;
            State         = InuState.Follow;
            return;
        }

        if (root != null)
        {
            bool setCurrent = false;

            if (currentNode == null)
            {
                closest     = null;
                closest     = SetClosest(closest, homeNode, nodes, rb);
                currentNode = closest;
                if (previous == null)
                {
                    previous  = currentNode;
                    previous2 = previous;
                }
                setCurrent = true;
            }

            if (currentNode != null)
            {
                currentNodePosition = new Vector3(currentNode.Col * 6 + 8, currentNode.Floor * 30, currentNode.Row * 6 + 8);

                if (setCurrent == false)
                {
                    if (Vector3.Distance(transform.position, currentNodePosition) < 2)
                    {
                        lookTimer = 4;
                        agent.SetDestination(transform.position);
                        state = InuState.LookAround;

                        /*{
                         *  MazeNode closest = null;
                         *  closest = UpdateClosest(closest, nodes, currentNode, previous, previous2, rb);
                         *  if (closest != null)
                         *  {
                         *      previous2 = previous;
                         *      previous = currentNode;
                         *      currentNode = closest;
                         *  }
                         *
                         *  if (Vector3.Distance(transform.position, currentNodePosition) < 2)
                         *  {
                         *      lookTimer = 6;
                         *          agent.SetDestination(transform.position);
                         *          state = InuState.LookAround;
                         *  }
                         * }
                         */
                        if (currentNode != null)
                        {
                            currentNodePosition = new Vector3(currentNode.Col * 6 + 8, currentNode.Floor * 30, currentNode.Row * 6 + 8);
                        }
                    }
                    agent.SetDestination(currentNodePosition);
                }
            }
        }
    }
Exemple #2
0
    void LateUpdate()
    {
        if (TestDebug)
        {
            print(state);
        }
        if (actorID == null)
        {
            actorID = GetComponent <Actor>();
        }

        if (controller == null)
        {
            controller = GetComponent <CharacterController>();
        }

        if (PlayerObject != null)
        {
            playerTransform = PlayerObject.transform;
        }
        else
        {
            playerTransform = null;
        }

        if (stunTimer > 0)
        {
            if (state != InuState.Stun)
            {
                state = InuState.Stun;
            }
        }

        if (stuckBlocker > 0)
        {
            stuckBlocker -= Time.deltaTime;
        }

        switch (state)
        {
        case InuState.Idle:
            idle();
            break;

        case InuState.Patrol:
            patrol();
            break;

        case InuState.LookAround:
            look();
            break;

        case InuState.Search:
            search();
            break;

        case InuState.Chase:
            chase();
            break;

        case InuState.Stalk:
            stalk();
            break;

        case InuState.Cornered:
            cornered();
            break;

        case InuState.Flee:
            flee();
            break;

        case InuState.Dead:
            dead();
            break;

        case InuState.Follow:
            follow();
            break;

        case InuState.Stun:
            stun();
            break;
        }

        switch (animState)
        {
        case InuAnim.Idle:
            //print("doing idle");
            animIdle();
            break;

        case InuAnim.Walk:
            //print("doing walk");
            animWalk();
            break;

        case InuAnim.Creep:
            //print("doing creep");
            animCreep();
            break;

        case InuAnim.Run:
            //print("doing run");
            animRun();
            break;

        case InuAnim.Attack:
            //print("doing attack");
            animAttack();
            break;

        case InuAnim.Stunned:
            //print("doing stunned");
            animStunned();
            break;

        case InuAnim.Sit:
            //print("doing sit");
            animSit();
            break;
        }

        if (awake == true)
        {
            TurnTowardsPlayer(PlayerObject);
        }

        posTimer -= Time.deltaTime;
        if (posTimer <= 0)
        {
            posTimer    = 30;
            oldPosition = newPosition;
            newPosition = transform.position;
        }
        posTimer2 -= Time.deltaTime;
        if (posTimer2 <= 0)
        {
            posTimer2    = 25;
            oldPosition2 = oldPosition;
            oldPosition  = transform.position;
        }

        MoveYokai(controller, agent);
    }