Example #1
0
    IEnumerator attackDelay()
    {
        attacking    = true;
        attackTimer  = 0;
        currBehavior = behaviorState.ATTACKING;
        yield return(new WaitForSeconds(0.5f));

        attacking    = false;
        currBehavior = behaviorState.PATROLLING;
    }
Example #2
0
 void Stopped()
 {
     damageBox.enabled = false;
     canTakeDamage     = true;
     GetComponent <SpriteRenderer> ().sprite = safeSprite;
     if (pauseTimeTimer < pauseTime)
     {
         pauseTimeTimer += Time.deltaTime;
         GetComponent <SpriteRenderer> ().color = Color.Lerp(Color.gray, Color.white, (pauseTimeTimer / pauseTime) * 1.0f);
     }
     else
     {
         currBehavior   = behaviorState.PATROLLING;
         pauseTime      = Random.Range(pauseTimemin, pauseTimemax);
         pauseTimeTimer = 0;
         GetComponent <SpriteRenderer> ().sprite = dangerSprite;
         GetComponent <SpriteRenderer> ().color  = Color.white;
         damageBox.enabled = true;
     }
     moveVector.x = 0;
     _velocity.x  = 0;
 }
Example #3
0
    void Behavior()
    {
        if (_controller.isGrounded)
        {
            _velocity.y = 0;
        }

        if (Vector2.Distance(transform.position, target.position) < aggroRange)
        {
            currBehavior = behaviorState.AGGRO;
        }


        if (Vector2.Distance(transform.position, target.position) < aggroRange / 2)
        {
            if (attackTimer < attackTime && !attacking)
            {
                attackTimer += Time.deltaTime;
            }
            else if (attackTimer > attackTime && !attacking)
            {
                attackTimer  = 0;
                currBehavior = behaviorState.ATTACKING;
            }
        }

        else if (Vector2.Distance(transform.position, target.position) < aggroRange + 5 && currBehavior == behaviorState.AGGRO && !attacking)          // Must leave further than the edge of the aggro range to get away from aggro.
        {
            if (aggroTimer >= aggroFalloff)
            {
                currBehavior = behaviorState.PATROLLING;
            }
            else
            {
                aggroTimer += Time.deltaTime;
            }
        }

        if ((_controller.collisionState.left || _controller.collisionState.right) && _controller.isGrounded && !jumped)
        {
            if (moveVector.y >= -0.1f)
            {
                jumped      = true;
                _velocity.y = Mathf.Sqrt(3f - gravity);
            }
        }

        if (jumped = true && _controller.isGrounded)
        {
            jumped = false;
        }


        if (!knockedBack)
        {
            switch (currBehavior)
            {
            case behaviorState.PATROLLING:
                Patrolling();
                break;

            case behaviorState.AGGRO:
                Aggro();
                break;

            case behaviorState.ATTACKING:
                Attack();
                break;

            default:
                Patrolling();
                break;
            }
        }

        //Handle direction facing based onmovement vector
        if (moveVector.normalized.x < 0)
        {
            GetComponent <SpriteRenderer> ().flipX = true;
        }
        else
        {
            GetComponent <SpriteRenderer> ().flipX = false;
        }
    }
Example #4
0
    void Behavior()
    {
        if (_controller.isGrounded)
        {
            _velocity.y = 0;
        }

        if (attackTimer < attackTime && !attacking && currBehavior != behaviorState.STOP)
        {
            attackTimer += Time.deltaTime;
        }
        else if (attackTimer > attackTime && !attacking && currBehavior != behaviorState.STOP)
        {
            attackTimer  = 0;
            currBehavior = behaviorState.ATTACKING;
        }

        if (pauseDelayTimer < pauseDelay && currBehavior != behaviorState.STOP)
        {
            GetComponent <SpriteRenderer> ().color = Color.Lerp(Color.white, Color.gray, (pauseDelayTimer / pauseDelay) * 1.0f);
            pauseDelayTimer += Time.deltaTime;
        }
        else
        {
            currBehavior    = behaviorState.STOP;
            pauseDelayTimer = 0;
            pauseDelay      = Random.Range(pauseDelaymin, pauseDelaymax);
        }



        if (jumped = true && _controller.isGrounded)
        {
            jumped = false;
        }


        if (!knockedBack)
        {
            switch (currBehavior)
            {
            case behaviorState.PATROLLING:
                Patrolling();
                break;

            case behaviorState.ATTACKING:
                Attack();
                break;

            case behaviorState.STOP:
                Stopped();
                break;

            default:
                Patrolling();
                break;
            }
        }

        //Handle direction facing based onmovement vector
        if (moveVector.normalized.x < 0)
        {
            GetComponent <SpriteRenderer> ().flipX = true;
        }
        else
        {
            GetComponent <SpriteRenderer> ().flipX = false;
        }
    }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        // Animation updates
        animator.SetFloat("Speed", speed);
        animator.SetBool("isDrained", drained);
        animator.SetBool("isScared", currentBehavior.Equals(behaviorState.Fleeing));



        if (seesPlayer)
        {
            sightLine.enabled = true;
            //render line
            Debug.LogError("enemy sees you!");
            sightLine.SetPosition(0, new Vector3(head.position.x, head.position.y, head.position.z));
            sightLine.SetPosition(1, new Vector3(playerScript1.gameObject.transform.position.x, playerScript1.gameObject.transform.position.y, playerScript1.gameObject.transform.position.z));

            lastPlayerLocation = new Vector3(Player1.transform.position.x, Player1.transform.position.y, Player1.transform.position.z);
            if (hostile)
            {
                chasingPlayer = true;
            }
            else
            if (!hostile)
            {
                currentBehavior = behaviorState.Fleeing;
                idleTimer       = 0;

                screamTimer += Time.deltaTime;
                if (screamTimer > 5)
                {
                    sourceOfAudio.PlayOneShot(randomScream());
                    screamTimer = 0;
                }
            }
        }
        else if (!seesPlayer)
        {
            sightLine.enabled = false;
        }

        if (distanceToPlayer >= 20 && !seesPlayer || distanceToPlayer > 50)
        {
            chasingPlayer = false;
        }

        //agent moves towards
        if (chasingPlayer)
        {
            Debug.LogError("ENEMY IS CHASING PLAYER");
            agent.SetDestination(playerScript1.transform.position);
            agent.speed = 5;
        }

        // lose sight of the player go to his last known location
        if (chasingPlayer && !seesPlayer)
        {
            Debug.LogError("ENEMY IS CHASING PLAYER");
            agent.SetDestination(lastPlayerLocation);
            agent.speed = 5;
        }

        //gives up chasing the player
        if (chasingPlayer && distanceToPlayerConstant > 20 && !seesPlayer)
        {
            chasingPlayer   = false;
            currentBehavior = behaviorState.Walking;
        }

        //if agent catches you go into failure state
        if (chasingPlayer && distanceToPlayerConstant < 1)//distanceToPlayer < 0.5f)
        {
            SceneManager.LoadScene("Failure-Captured");
        }

        if (chasingPlayer && distanceToPlayerConstant > 10)//distanceToPlayer < 0.5f)
        {
            currentBehavior = behaviorState.Walking;
        }
        if (currentBehavior == behaviorState.Fleeing && currentBehavior != behaviorState.Walking)
        {
            currentWalkTarget = null;
            // agent.prio
            Vector3 target = new Vector3(currentFleeTarget.transform.position.x, currentFleeTarget.transform.position.y, currentFleeTarget.transform.position.z);
            agent.speed = 15;
            agent.SetDestination(target);
        }
        //currentBehavior = behaviorState.Walking;
        if (NPCcontroller.velocity.z < 0.01f && currentBehavior == behaviorState.Walking)
        {
            // Debug.LogError("NPC STUCK AT" + transform.position);
        }
        //
        if (useIdleTimer && idleTimer > 0)
        {
            idleTimer -= 1 * Time.deltaTime;
        }
        else if (useIdleTimer)
        {
            idleTimer = 5;
        }

        if (useIdleTimer && currentBehavior == behaviorState.Idle && idleTimer <= 0)
        {
            currentBehavior   = behaviorState.Walking;
            currentWalkTarget = allWalkTargets[Random.Range(0, allWalkTargets.Count)];
        }


        if (currentBehavior == behaviorState.Walking && currentBehavior != behaviorState.Fleeing)
        {
            Vector3 target = new Vector3(currentWalkTarget.transform.position.x, currentWalkTarget.transform.position.y, currentWalkTarget.transform.position.z);
            //agent.SetDestination(target);
            if (!hostile && !drained && useIdleTimer)
            {
                agent.SetDestination(target);
            }
            else if (drained)
            {
                this.enabled = false;
                Destroy(agent);
            }
            if (hostile && !chasingPlayer)
            {
                agent.speed = 2.5f;
                agent.SetDestination(target);
            }


            distanceToTarget = Vector3.Distance(currentWalkTarget.transform.position, transform.position);

            if (distanceToTarget < 5f)
            {
                currentBehavior = behaviorState.Idle;
                //MAKE THIS A RANDOM RANGE
                idleTimer = Random.Range(10, 20);
            }
        }

        if (distanceToPlayerConstant > cullingDistance)
        {
            Destroy(this.gameObject);
        }

        if (CARE <= 0)
        {
            drained = true;
        }

        //DO THE LIGHT LOGIC ONLY ONE NPC AT A TIME AND ONLY IF IT CAN BE DRAINED
        if (tooCloseMeter >= secsTilPassout)
        {
            Debug.Log("BOOM");
            Destroy(this.gameObject);
        }

        distanceToPlayerConstant = Vector3.Distance(Player1.transform.position, this.gameObject.transform.position);

        if (playerScript1.shootTarget == this.gameObject.transform)
        {
            distanceToPlayer = Vector3.Distance(Player1.transform.position, this.gameObject.transform.position);
        }

        if (distanceToPlayer < tooFarDistance + 1)
        {
            if (distanceToPlayer <= tooCloseDistance && playerScript1.shootTarget == this.gameObject.transform)
            {
                tooClose = true;
                draining = false;
                playerScript1.distanceLight.enabled   = true;
                playerScript1.distanceLight.intensity = 1;
                playerScript1.distanceLight.color     = Color.red;//(Color.red / 1f) * Time.deltaTime;
                playerScript1.goldieLocks             = false;
                playerScript1.tooCloseText.enabled    = true;
                playerScript1.isExtracting            = draining;
            }
            else
            if (distanceToPlayer > tooCloseDistance)
            {
                tooClose = false;
                playerScript1.tooCloseText.enabled = false;
            }

            if (!hostile && tooClose && tooCloseMeter < secsTilPassout)
            {
                tooCloseMeter += 1f * Time.deltaTime;
            }
            else
            if (!tooClose && tooCloseMeter < 0f)
            {
                tooCloseMeter -= 1f * Time.deltaTime;
            }

            if (distanceToPlayer >= tooFarDistance || CARE <= 0)
            {
                tooFar        = true;
                draining      = false;
                tooCloseMeter = 0f;
                //playerScript1.distanceLight.color -= (Color.white);// / 2.0f) * Time.deltaTime;
                playerScript1.distanceLight.enabled   = true;
                playerScript1.distanceLight.color     = Color.white;
                playerScript1.distanceLight.intensity = 0.5f;
                playerScript1.isExtracting            = draining;
            }
            else
            if (distanceToPlayer < tooFarDistance)
            {
                tooFar = false;
            }
            if (!tooClose && !tooFar && playerScript1.shootTarget == this.gameObject.transform && CARE > 0)
            {
                playerScript1.distanceLight.enabled   = true;
                playerScript1.distanceLight.intensity = 1;
                playerScript1.distanceLight.color     = Color.yellow;
                playerScript1.goldieLocks             = true;
            }
        }

        if (draining)
        {
            CARE -= 1 * Time.deltaTime;
            //player score += scoreamount
            playerScript1.CAREstolen += 1 * Time.deltaTime;
        }
        //select runpoint at random
        // AI state = calm
        //sees player
        //AI state = run
        //if AI state = run
        //navigate to run point

        if (Input.GetButton("Fire1"))
        {
            Debug.Log("Player trying to drain");

            // if not too close and not too far and //not too far from cube
            if (!tooClose && CARE > 0 && distanceToPlayerConstant < tooFarDistance)
            {
                playerScript1.distanceLight.enabled = true;
                //assign that NPC to target
                playerScript1.shootTarget = this.transform;
                Debug.Log("Setting drain to true");
                //start draining
                draining = true;
                playerScript1.distanceLight.intensity = 1;
                playerScript1.distanceLight.color     = Color.green;
                playerScript1.isExtracting            = draining;
                playerScript1.goldieLocks             = false;
            }
        }
        if (Input.GetButtonUp("Fire1") || CARE <= 0 || distanceToPlayer >= tooFarDistance)
        {
            draining = false;
            playerScript1.isExtracting = draining;
        }
        // void OnMouseDown()
        //   {
        //assign that NPC to target
        //    playerScript1.shootTarget = this.transform;
        // if not too close and not too far and //not too far from cube
        //    if (!tooClose && !tooFar)
        //   {
        //       //start draining
        //      draining = true;
        //  }


        //set rotation of model look at target
        // cinemachine lookat = shoottarget
    }