Example #1
0
    void CheckSprintStateStart()
    {
        if (!isSprinting)
        {
            MonsterSprinting.Invoke();

            if (Vector3.Distance(transform.position, target.transform.position) < 20)
            {
                monsterAnimator.PlayRoarSound();
            }

            isSprinting = true;
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        monsterOnScreen = IsInView(gameObject, monster.gameObject);

        /*
         * planes = GeometryUtility.CalculateFrustumPlanes(cam);
         * if (GeometryUtility.TestPlanesAABB(planes, monsterCollider.bounds))
         * {
         *  monsterOnScreen = true;
         * }
         * else
         * {
         *  monsterOnScreen = false;
         * }
         */

        if (monsterOnScreen)
        {
            timer += Time.deltaTime;
            if (timer >= timerForAggro)
            {
                timer           = 0;
                monster.isAggro = true;
            }

            if (!seeMonsterFirstTime && monsterAnimator.enabled && Vector3.Distance(transform.position, monster.transform.position) < 20)
            {
                monsterAnimator.PlayRoarSound();

                seeMonsterFirstTime = true;
            }
        }
        else if (Vector3.Distance(transform.position, monster.transform.position) < 20)
        {
            monster.isAggro = true;
        }
        else
        {
            monster.isAggro = false;
        }

        if (charController.isGrounded)
        {
            moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);

            if (moveDirection.x != 0 || moveDirection.z != 0)
            {
                isMoving = true;
            }
            else
            {
                isMoving = false;

                startMoveSound = false;
            }

            if (Input.GetKey(KeyCode.LeftShift))
            {
                isWalking     = false;
                moveDirection = moveDirection * sprintSpeed;
            }
            else
            {
                isWalking     = true;
                moveDirection = moveDirection * moveSpeed;
            }
        }

        // apply gravity
        moveDirection.y = moveDirection.y - (gravity * Time.deltaTime);

        // move controller;
        charController.Move(moveDirection * Time.deltaTime);

        if (isMoving)
        {
            if (Input.GetKeyDown(KeyCode.LeftShift))
            {
                PlaySound(0, Random.Range(sprintingVolume - 0.03f, sprintingVolume + 0.03f), Random.Range(sprintingPitch - 0.03f, sprintingPitch + 0.03f));
            }
            else if (Input.GetKeyUp(KeyCode.LeftShift))
            {
                PlaySound(0, Random.Range(moveVolume - 0.03f, moveVolume + 0.03f), Random.Range(movePitch - 0.03f, movePitch + 0.03f));
            }
            // start move sound
            else if (!startMoveSound)
            {
                PlaySound(0, Random.Range(moveVolume - 0.03f, moveVolume + 0.03f), Random.Range(movePitch - 0.03f, movePitch + 0.03f));
                startMoveSound = true;
            }
        }

        /*
         * // play moving sound while player is moving
         * if (charController.isGrounded && isMoving && canPlaySound)
         * {
         *  if (isWalking)
         *  {
         *      PlaySound(0, Random.Range(moveVolume - 0.03f, moveVolume + 0.03f), Random.Range(movePitch - 0.03f, movePitch + 0.03f));
         *  }
         *  else
         *  {
         *      PlaySound(0, Random.Range(sprintingVolume - 0.03f, sprintingVolume + 0.03f), Random.Range(sprintingPitch - 0.03f, sprintingPitch + 0.03f));
         *  }
         * }
         */

        Interact();
    }