Exemplo n.º 1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //if (Time.timeScale == 0f) return;

        if (HEALTH <= 0f)
        {
            Death();
        }

        //set velocity Y to 0 if has collisions
        if (controller.collisions.above || controller.collisions.below)
        {
            velocity.y = 0f;
        }

        //Landing
        if (!wasGrounded && controller.collisions.below == true && !isCoyoteTime)
        {
            LandingSFX();
        }

        //start Jump
        if (wasGrounded == true && controller.collisions.below == false && velocity.y < 0)
        {
            isCoyoteTime = true;
            StartCoroutine(CoyoteTime());
        }
        wasGrounded = controller.collisions.below;

        if (startJump || (bufferJump && controller.collisions.below))
        {
            velocity.y   = maxJumpVelocity;
            startJump    = false;
            anim.jumping = true;

            if (GetComponent <Player_Alex>())
            {
                GetComponentInChildren <SFX_Manager_Alex>().PlayAudio2("walk");
            }
            else if (GetComponent <Player_Garrett>())
            {
                GetComponentInChildren <SFX_Manager_Garrett>().PlayAudio2("walk");
            }

            if (bufferJump)
            {
                bufferJump = false;
            }
        }

        if (stopJump)
        {
            if (velocity.y > minJumpVelocity)
            {
                velocity.y = minJumpVelocity;
            }
            stopJump = false;
        }



        //start crouch
        if (controller.collisions.below && startCrouch)
        {
            //edit here for crouch animation

            //camera control
            if (!cameraControlDelayStart && !cameraControlDelay)
            {
                StartCoroutine(CameraControlDelay());
            }
            if (cameraControlDelay)
            {
                //for shaking screen apparently
                //impulseSent = true;
                //source = GetComponent<Cinemachine.CinemachineImpulseSource>();
                //source.GenerateImpulse(Camera.main.transform.up * -1);
                //insert impulse here for virtual camera
            }
            //else impulseSent = false;
        }

        //float moveInput = inputActions.Platforming.Move.ReadValue<float>();
        float targetVelocityX;

        if (anim.anim.GetBool("isHit") == true)
        {
            targetVelocityX = 5f * -anim.direction;
        }
        else if (movementLock && (controller.collisions.below || controller.collisions.grounded))
        {
            targetVelocityX = GetTargetVelocity();
        }
        else
        {
            targetVelocityX = moveSpeed * moveInput;
        }

        velocity.x  = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, accelTime);
        velocity.y += gravity * Time.deltaTime;
        controller.Move(velocity * Time.deltaTime);

        //Check Animations
        anim.CheckAnims(!movementLock? moveInput : anim.direction, velocity, controller.collisions.below || controller.collisions.grounded, isCrouched, isAttacking);
    }