Пример #1
0
 void stun()
 {
     posTimer   = 30;
     posTimer2  = 25;
     stunTimer -= Time.deltaTime;
     if (stunTimer <= 0)
     {
         seen           = false;
         seen           = SeeObject(PlayerObject, LevelMask, home);
         foundFootprint = SeeFootprint(allNodes, LevelMask, home);
         if (seen)
         {
             State = TakaState.Chase;
         }
         else if (foundFootprint != null && awake == true)
         {
             nextFootprint = foundFootprint;
             State         = TakaState.Follow;
         }
         else
         {
             State = TakaState.Idle;
         }
     }
 }
Пример #2
0
 void Stun()
 {
     State     = TakaState.Stun;
     stunTimer = 20;
     agent.SetDestination(transform.position);
     fleeingInu = false;
 }
Пример #3
0
 void idle()
 {
     posTimer  = 30;
     posTimer2 = 25;
     if (FleeInu(LevelMask, home))
     {
         State = TakaState.Flee;
         return;
     }
     seen = false;
     seen = SeeObject(PlayerObject, LevelMask, home);
     if (seen)
     {
         awake = true;
         State = TakaState.Chase;
         return;
     }
     foundFootprint = SeeFootprint(allNodes, LevelMask, home);
     if (foundFootprint != null)
     {
         nextFootprint = foundFootprint;
         State         = TakaState.Follow;
     }
     else if (root != null)
     {
         State = TakaState.Patrol;
     }
 }
Пример #4
0
    void chase()
    {
        if (FleeInu(LevelMask, home))
        {
            State = TakaState.Flee;
            return;
        }
        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       = TakaState.Flee;
                    return;
                }
            }
        }
        agent.ResetPath();
        seen = false;
        seen = SeeObject(PlayerObject, LevelMask, home);
        if (!seen)
        {
            foundFootprint = SeeFootprint(allNodes, LevelMask, home);
            if (foundFootprint != null)
            {
                nextFootprint = foundFootprint;
                State         = TakaState.Follow;
            }
            else
            {
                State = TakaState.Idle;
            }
        }

        agent.SetDestination(PlayerObject.transform.position);

        dest = PlayerObject.transform.position;

        if (Vector3.Distance(transform.position, dest) < 5)
        {
            //if taka close enough to player taunt them
            State = TakaState.Taunt;
            agent.SetDestination(transform.position);
            //gameObject.transform.rotation = startingRotation;
        }
    }
Пример #5
0
    void look()
    {
        posTimer   = 30;
        posTimer2  = 25;
        lookTimer -= Time.deltaTime;
        if (TestDebug)
        {
            print(lookTimer);
        }
        if (FleeInu(LevelMask, home))
        {
            State = TakaState.Flee;
            return;
        }
        seen = false;
        seen = SeeObject(PlayerObject, LevelMask, home);
        if (seen)
        {
            //if player has been seen chase
            awake = true;
            State = TakaState.Chase;
            return;
        }
        foundFootprint = SeeFootprint(allNodes, LevelMask, home);
        if (foundFootprint != null)
        {
            //if footprints found follow
            nextFootprint = foundFootprint;
            State         = TakaState.Follow;
            return;
        }
        transform.Rotate(Vector3.up * (360 * Time.deltaTime));
        if (lookTimer <= 0)
        {
            if (root != null)
            {
                //old destination reached, update patrol path
                closest = null;
                closest = UpdateClosest(closest, nodes, currentNode, previous, previous2, rb);
                if (closest != null)
                {
                    previous2   = previous;
                    previous    = currentNode;
                    currentNode = closest;
                }

                State = TakaState.Patrol;
                return;
            }
        }
    }
Пример #6
0
    void Start()
    {
        //intialize variables
        rb               = GetComponent <Rigidbody>();
        home             = gameObject.transform.position;
        distanceToFloor  = home.y + 0.1F;
        startingRotation = gameObject.transform.rotation;
        actorID          = GetComponent <Actor>();
        State            = TakaState.Idle;
        animState        = TakaAnim.Idle;
        awake            = false;
        PlayerObject     = GameObject.FindGameObjectWithTag("Player");
        cam              = Camera.main;
        oldPosition      = home;
        posTimer         = 6;
        posTimer2        = 3;
        root             = MazeGenerator.getSectionBasedOnLocation(home);
        if (root != null)
        {
            nodes = MazeGenerator.GetIntersectionNodes(root);
        }
        currentNode          = StartingNode;
        agent                = GetComponent <NavMeshAgent>();
        agent.updatePosition = false;
        agent.updateRotation = true;
        agent.nextPosition   = transform.position;
        //transform.position = agent.nextPosition;
        agent.Warp(transform.position);
        fleeingInu = false;

        column = (int)((home.x - 8) / 6);
        row    = (int)((home.z - 8) / 6);

        allNodes = MazeGenerator.nodesInSection(root);

        foreach (MazeNode n in allNodes)
        {
            if (n.Col == column && n.Row == row)
            {
                homeNode = n;
            }
        }
    }
Пример #7
0
 void safeZoneCollision()
 {
     State = TakaState.Flee;
 }
Пример #8
0
    void follow()
    {
        //agent.ResetPath();
        if (FleeInu(LevelMask, home))
        {
            State = TakaState.Flee;
            return;
        }
        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       = TakaState.Flee;
                    return;
                }
            }
        }
        seen = false;
        seen = SeeObject(PlayerObject, LevelMask, home);
        if (seen)
        {
            State         = TakaState.Chase;
            nextFootprint = null;
            return;
        }
        if (nextFootprint == null)
        {
            foundFootprint = SeeFootprint(allNodes, LevelMask, home);
            if (foundFootprint == null)
            {
                nextFootprint = foundFootprint;
                State         = TakaState.Idle;
            }
            if (foundFootprint != null)
            {
                nextFootprint = foundFootprint;
                agent.SetDestination(foundFootprint.transform.position);
            }
        }
        else
        {
            if (Vector3.Distance(transform.position, nextFootprint.transform.position) < 1)
            {
                nextFootprint = nextFootprint.getNext();
            }

            agent.SetDestination(nextFootprint.transform.position);
        }
    }
Пример #9
0
    void flee()
    {
        posTimer   = 30;
        posTimer2  = 25;
        fleeTimer -= Time.deltaTime;
        if (fleeTimer <= 0)
        {
            seen = false;
            seen = SeeObject(PlayerObject, LevelMask, home);
            if (seen)
            {
                awake = true;
                State = TakaState.Chase;
                return;
            }
            foundFootprint = SeeFootprint(allNodes, LevelMask, home);
            if (foundFootprint != null)
            {
                nextFootprint = foundFootprint;
                State         = TakaState.Follow;
                return;
            }
        }

        agent.ResetPath();

        if (mr == null)
        {
            //mr = gameObject.GetComponentInChildren<MeshRenderer>();
            mr = gameObject.GetComponentInChildren <Transform>();
        }
        //if taka has grown, shrink it
        if (shrinkTimer > 0)
        {
            shrinkTimer             -= Time.deltaTime;
            mr.transform.localScale -= new Vector3(0, 0.002F, 0);
            mr.transform.position   -= new Vector3(0, 0.001F, 0);
            distanceToFloor         -= 0.01F;
        }

        targetPos = new Vector3();
        if (fleeTarget == null)
        {
            presentNode = new MazeNode();
            obstacle    = false;
            column      = homeNode.Col;
            row         = homeNode.Row;

            foreach (MazeNode n in MazeGenerator.nodesInSection(root))
            {
                if (n.Col == column && n.Row == row)
                {
                    presentNode = n;
                }
            }

            possiblePath  = MazeGenerator.GetPath2(presentNode, homeNode);
            prevCheckNode = presentNode;

            foreach (MazeNode n in possiblePath)
            {
                if (n.EnemyPathNode || GameManager.trapNode(n))
                {
                    fleeTarget = prevCheckNode;
                    obstacle   = true;
                    break;
                }
                prevCheckNode = n;
            }
            if (!obstacle)
            {
                fleeTarget = homeNode;
            }

            fleePath = MazeGenerator.GetPath2(presentNode, fleeTarget);
            foreach (MazeNode n in fleePath)
            {
                n.EnemyPathNode = true;
            }
        }

        targetPos = new Vector3(fleeTarget.Col * 6 + 8, fleeTarget.Floor * 30, fleeTarget.Row * 6 + 8);

        if (Vector3.Distance(transform.position, targetPos) < 2)
        {
            State = TakaState.Idle;
            gameObject.transform.rotation = startingRotation;
        }

        agent.SetDestination(targetPos);

        /*
         * if (transform.position.x < home.x + 2 && transform.position.x > home.x - 2)
         * {
         *  if (transform.position.z < home.z + 2 && transform.position.z > home.z - 2)
         *  {
         *      State = TakaState.Idle;
         *      gameObject.transform.rotation = startingRotation;
         *  }
         * }
         *
         * agent.SetDestination(home);
         */
    }
Пример #10
0
    //function to execute in taunt state
    void taunt()
    {
        posTimer  = 30;
        posTimer2 = 25;
        if (FleeInu(LevelMask, home))
        {
            State = TakaState.Flee;
            return;
        }
        //rayDirection = playerTransform.position - transform.position;
        //rayDirection.y = 0;
        playerCloseToEnemy = Vector3.Distance(playerTransform.position, transform.position) < TauntDistance;
        if (!playerCloseToEnemy)
        {
            seen = false;
            seen = SeeObject(PlayerObject, LevelMask, home);
            if (seen)
            {
                State = TakaState.Chase;
                return;
            }
            foundFootprint = SeeFootprint(allNodes, LevelMask, home);
            if (foundFootprint != null)
            {
                nextFootprint = foundFootprint;
                State         = TakaState.Follow;
                return;
            }
            else if (StartingNode != null)
            {
                State = TakaState.Patrol;
                return;
            }
            else
            {
                State = TakaState.Idle;
                return;
            }
        }

        //play taunt sounds
        if (mr == null)
        {
            //mr = gameObject.GetComponentInChildren<MeshRenderer>();
            mr = gameObject.GetComponentInChildren <Transform>();
        }
        //make the taka appear to grow taller
        if (growthTimer > 0)
        {
            growthTimer             -= Time.deltaTime;
            mr.transform.localScale += new Vector3(0, 0.002F, 0);
            mr.transform.position   += new Vector3(0, 0.001F, 0);
            distanceToFloor         += 0.01F;
        }
        //if player has avoided looking up for a full taunt cycle the taka backs off
        else if (growthTimer <= 0)
        {
            State = TakaState.Flee;
            return;
        }

        //if player looks up while taunted, kill it
        if (playerLookingUp())
        {
            if (UnityEngine.XR.XRDevice.isPresent)
            {
                player = PlayerObject.GetComponentInParent <Actor>();
                GameManager.Instance.ActorKilled(actorID, player);
            }
            else
            {
                GameManager.Instance.ActorKilled(actorID, PlayerObject.GetComponent <Actor>());
            }
            GameManager.Instance.GameOver();
            PlayerObject.SetActive(false);
            if (TestDebug)
            {
                print("GameOver");
            }
        }
    }
Пример #11
0
    void patrol()
    {
        if (FleeInu(LevelMask, home))
        {
            State = TakaState.Flee;
            return;
        }
        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       = TakaState.Flee;
                    return;
                }
            }
        }
        seen = false;
        seen = SeeObject(PlayerObject, LevelMask, home);
        if (seen)
        {
            awake = true;
            State = TakaState.Chase;
            return;
        }

        foundFootprint = SeeFootprint(allNodes, LevelMask, home);

        if (foundFootprint != null)
        {
            nextFootprint = foundFootprint;
            State         = TakaState.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 = TakaState.LookAround;

                        /*MazeNode closest = null;
                         * closest = UpdateClosest(closest, nodes, currentNode, previous, previous2, rb);
                         * if (closest != null)
                         * {
                         *  previous2 = previous;
                         *  previous = currentNode;
                         *  currentNode = closest;
                         * }*/
                        //lookTimer = 6;
                        //agent.SetDestination(transform.position);
                        //state = TakaState.LookAround;
                    }

                    if (currentNode != null)
                    {
                        currentNodePosition = new Vector3(currentNode.Col * 6 + 8, currentNode.Floor * 30, currentNode.Row * 6 + 8);
                    }
                }
                agent.SetDestination(currentNodePosition);
            }
        }
    }
Пример #12
0
    void LateUpdate()
    {
        if (TestDebug)
        {
            print("Taka state " + state);
        }
        if (actorID == null)
        {
            actorID = GetComponent <Actor>();
        }

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

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

        //manage state machine each update, call functions based on state

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

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

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

        case TakaState.Patrol:
            patrol();
            break;

        case TakaState.LookAround:
            look();
            break;

        case TakaState.Search:
            search();
            break;

        case TakaState.Chase:
            chase();
            break;

        case TakaState.Taunt:
            taunt();
            break;

        case TakaState.Flee:
            flee();
            break;

        case TakaState.Dead:
            dead();
            break;

        case TakaState.Follow:
            follow();
            break;

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

        switch (animState)
        {
        case TakaAnim.Idle:
            animIdle();
            break;

        case TakaAnim.Walk:
            animWalk();
            break;

        case TakaAnim.Run:
            animRun();
            break;

        case TakaAnim.Attack:
            animAttack();
            break;

        case TakaAnim.Stunned:
            animStunned();
            break;

        case TakaAnim.Taunt:
            animTaunt();
            break;

        case TakaAnim.Glare:
            animGlare();
            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;
        }

        if (distanceToFloor < 0.0F)
        {
            distanceToFloor = 0.0F;
        }

        MoveYokai(controller, agent);
    }