Пример #1
0
    void Update()
    {
        if (vi.GetButtonDown(Button.ACTION))
        {
            if (possessing != null)
            {
                ActivatePossessing();
            }
            else
            {
                Possess();
            }
        }
        if (vi.GetButtonDown(Button.JUMP))
        {
            if (possessing != null)
            {
                Unpossess();
            }
        }

        if (possessing)
        {
            return;
        }

        ////////////////////////////////////////////////////////
        // Move the player

        float h = vi.GetAxisRaw(Axis.HORIZONTAL) * speed;
        float v = vi.GetAxisRaw(Axis.VERTICAL) * speed;

        Vector2 move = new Vector2(h, v) * Time.deltaTime;

        bool flipSprite = (spriteRenderer.flipX ? (move.x > 0.01f) : (move.x < -0.01f));

        if (flipSprite)
        {
            spriteRenderer.flipX = !spriteRenderer.flipX;
        }

        if ((rb.position.x + move.x) > boundX || (rb.position.x + move.x) < -boundX)
        {
            move.x = 0;
        }
        if ((rb.position.y + move.y) > boundY || (rb.position.y + move.y) < -boundY)
        {
            move.y = 0;
        }

        rb.position += move;
    }
Пример #2
0
    // Update is used to set features regardless the active behaviour.
    void Update()
    {
        // Activate/deactivate aim by input.
        if (VirtualInput.GetAxisRaw(aimButton) != 0 && !aim)
        {
            StartCoroutine(ToggleAimOn());
        }
        else if (aim && VirtualInput.GetAxisRaw(aimButton) == 0)
        {
            StartCoroutine(ToggleAimOff());
        }

        // No sprinting while aiming.
        canSprint = !aim;

        // Toggle camera aim position left or right.
        if (aim && VirtualInput.GetButtonDown(shoulderButton))
        {
            aimCamOffset.x   = aimCamOffset.x * (-1);
            aimPivotOffset.x = aimPivotOffset.x * (-1);
        }

        // Set aim boolean on the Animator Controller.
        behaviourManager.GetAnim.SetBool(aimBool, aim);
    }
Пример #3
0
    protected override void ComputeVelocity()
    {
        applyPhysics = !wallLatched;

        if (wallLatchCooldownTimer > 0 && !wallLatched)
        {
            wallLatchCooldownTimer -= Time.deltaTime;
        }

        // Play latch sound if just latched
        if (wallLatched)
        {
            if (!wasWallLatched)
            {
                audioSource.PlayOneShot(latchSound);
            }
        }
        else if (wallLatchCooldownTimer > 0)
        {
            wallLatchCooldownTimer -= Time.deltaTime;
        }
        wasWallLatched = wallLatched;


        // Compute Velocity
        Vector2 move = Vector2.zero;

        move.x = vi.GetAxisRaw(Axis.HORIZONTAL) * speed;

        if (vi.GetButtonDown(Button.JUMP) && (grounded || wallLatched))
        {
            velocity.y = jumpVelocity;

            wallLatchCooldownTimer = wallLatchCooldown;
            wallLatched            = false;
            animator.SetBool("wallLatched", wallLatched);

            // Play jump sound
            audioSource.PlayOneShot(jumpSound);
        }
        else if (vi.GetButtonUp(Button.JUMP) && canCancelJump)
        {
            if (velocity.y > 0)
            {
                velocity.y = velocity.y * jumpCancelVelocityModifier;
            }
        }

        bool flipSprite = (spriteRenderer.flipX ? (move.x > 0.01f) : (move.x < -0.01f));

        if (flipSprite && !wallLatched)
        {
            spriteRenderer.flipX = !spriteRenderer.flipX;
        }

        animator.SetBool("grounded", grounded);
        animator.SetFloat("velocityX", Mathf.Abs(velocity.x) / speed);

        targetVelocity = move;
    }