private void FixedUpdate()
    {
        if (!dropThroughPlatforms && AtlasInputManager.getKey("Jump") && isCrouching())
        {
            dropThroughPlatforms = true;
            controller.collisions.Reset();
            Vector3 downVec = Vector3.down;
            controller.VerticalCollisions(ref downVec);
            controller.checkGrounded(downVec.y);
        }
        anim.SetBool("isGrounded", isGrounded());
        if (isGrounded())
        {
            coyoteTime = maxCoyoteTime;
        }
        else if (coyoteTime > 0)
        {
            coyoteTime--;
        }

        if (state == State.Reset || state == State.Wait || state == State.Menu)
        {
            return;
        }
        controller.Move(velocity * Time.deltaTime);
        controller.checkWallSlide(facing);
        isWallSliding();
        if (controller.collisions.above || controller.collisions.below)
        {
            velocity.y = 0;
        }
    }
    void handleBroom()
    {
        if (AtlasInputManager.getKeyPressed("Broom") ||
            AtlasInputManager.getKeyPressed("Down") ||
            (!AtlasInputManager.getKey("Broom") &&
             AtlasInputManager.Instance.holdBroom))
        {
            endBroom();
            return;
        }
        if (AtlasInputManager.getKeyPressed("Jump") && canDoubleJump && resourceManager.Instance.getPlayerMana() >= 1)
        {
            endBroom();
            if (hasDoubleJump)
            {
                doubleJump();
            }
            return;
        }
        if ((facing == -1) ? controller.collisions.left : controller.collisions.right)
        {
            startBonk();
            return;
        }
        float vdir = 0 * AtlasInputManager.getAxisState("Dpad").y;

        velocity.y = moveSpeed / 2.0f * vdir;
        velocity.x = moveSpeed * 2 * facing;
    }
    // Update is called once per frame
    void Update()
    {
        if (!AtlasInputManager.getKey("Scout"))
        {
            Destroy(gameObject);
        }
        if (selectedPc && AtlasInputManager.getKeyPressed("Jump"))
        {
            textPanel.SetActive(true);
            textPanel.GetComponentInChildren <TextMeshProUGUI>().text = selectedPc.scoutMessage.Replace("\\n", "\n");
        }
        Vector2 velocity = AtlasInputManager.getAxisState("Dpad");

        transform.Translate(velocity * speed * Time.deltaTime);
    }
    //Ideally we can find a way to pause until  a certain condition is met
    //But what do we do about multiple pauseCoroutines?
    IEnumerator pauseCoroutine()
    {
        Vector2 prevVelocity  = velocity;
        State   prevState     = state;
        float   prevAnimSpeed = anim.speed;

        velocity   = Vector3.zero;
        state      = State.Wait;
        anim.speed = 0;

        while (AtlasInputManager.getKey("Scout"))
        {
            yield return(new WaitForEndOfFrame());
        }

        state      = prevState;
        velocity   = prevVelocity;
        anim.speed = prevAnimSpeed;
    }
 IEnumerator jumpCoroutine(bool dj = false)
 {
     for (int i = 0; i < variableJumpIncrements; i++)
     {
         if (!AtlasInputManager.getKey("Jump"))
         {
             if (dj)
             {
                 velocity.y = Mathf.Min(velocity.y, doubleJumpVelocity / 2.0f);
             }
             else
             {
                 velocity.y /= 4;
             }
             i = variableJumpIncrements;
             yield return(0);
         }
         yield return(new WaitForSeconds(4 / 60.0f));
     }
 }
Ejemplo n.º 6
0
 // Update is called once per frame
 void Update()
 {
     equipmentPanel.gameObject.SetActive(AtlasInputManager.getKey("DisplayEquipment"));
 }
    void handleMovement(float msMod = 1.0f, bool canJump = true, bool canTurnAround = true)
    {
        if (heldObject != null)
        {
            msMod  *= 0.5f;
            canJump = false;
        }

        Vector2 input = new Vector2(0, 0);

        if (!(state == State.WaitMoveable && isGrounded()))
        {
            input = new Vector2(AtlasInputManager.getAxisState("Dpad").x, AtlasInputManager.getAxisState("Dpad").y);
        }

        if (isGrounded() || coyoteTime > 0)
        {
            if (AtlasInputManager.getKeyPressed("Jump") && canJump)
            {
                firstJump();
            }
            if (AtlasInputManager.getKeyPressed("Broom"))
            {
                triggerBroomStart();
            }
            if (isGrounded())
            {
                if (!canBroom && state == State.Movement)
                {
                    canBroom = true;
                }
                canDoubleJump = true;
                resourceManager.Instance.restoreMana();
            }
        }
        else
        {
            if (canBroom && AtlasInputManager.getKeyPressed("Broom"))
            {
                if (wallRiding)
                {
                    flipHorizontal();
                    triggerBroomStart(fastBroom, facing);
                }
                else
                {
                    triggerBroomStart(fastBroom);
                }
                return;
            }

            if (hasWallJump && wallRiding && AtlasInputManager.getKeyPressed("Jump") && resourceManager.Instance.getPlayerMana() >= 2)
            {
                state = State.WallJumpInit;
                return;
            }

            if (hasDoubleJump && AtlasInputManager.getKeyPressed("Jump") && canJump && canDoubleJump && resourceManager.Instance.getPlayerMana() >= 1)
            {
                doubleJump();
            }
        }

        float currentMoveSpeed = moveSpeed;

        if (isCrouching())
        {
            currentMoveSpeed = 1.5f;
        }
        float targetVelocityX = input.x * currentMoveSpeed * msMod;

        anim.SetBool("isRunning", isGrounded() && (targetVelocityX != 0));
        anim.SetBool("isJumping", !isGrounded() && (velocity.y > 0) && canDoubleJump);
        anim.SetBool("isFalling", !isGrounded() && (velocity.y < -0.5f) && !controller.collisions.descendingSlope && !heldObject);
        anim.SetBool("wallSlide", wallRiding);
        if (wallRiding)
        {
            deformer.RemoveDeform("jump");
            deformer.RemoveDeform("fastfall");
        }

        if (canTurnAround)
        {
            setFacing(velocity.x);
        }

        velocity.x  = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? groundAccelerationTime : airAccelerationTime);
        velocity.y += gravity * Time.deltaTime * ((wallRiding && velocity.y <= 0) ? 0.5f : 1.0f);

        if (wallRiding && velocity.y < maxWallSlideVel)
        {
            velocity.y = maxWallSlideVel;
        }

        float termVel;

        if (fastFalling)
        {
            if (AtlasInputManager.getAxisState("Dpad").y >= 0 || isGrounded() || velocity.y > 0)
            {
                fastFalling = false;
            }
            termVel     = fastFallVel;
            velocity.y += gravity * Time.deltaTime;
        }
        else
        {
            termVel = maxFallVel;
            deformer.RemoveDeform("fastfall");
            if (AtlasInputManager.getKeyPressed("Down") && !isGrounded() && (velocity.y <= 0.5f || !AtlasInputManager.getKey("Jump")))
            {
                fastFalling = true;
                deformer.startDeform(new Vector3(0.85f, 1.4f, 1.0f), 0.2f, -1.0f, -1.0f, "fastfall", true);
            }
        }
        if (velocity.y < termVel)
        {
            velocity.y = termVel;
        }

        if (velocity.y <= 0 && controller.isSafePosition())
        {
            lastSafePosition = transform.position;
        }
    }