Example #1
0
    protected void Move()
    {
        if (Utilities.VectorEquals(direction, Vector3.right) && controller.Collisions.isRight)
        {
            direction = -Vector3.right;
        }
        else if (Utilities.VectorEquals(direction, -Vector3.right) && controller.Collisions.isLeft)
        {
            direction = Vector3.right;
        }

        controller.ApplyGravity(ref direction);

        controller.ApplyMovement(direction);
    }
    void BounceToLocation()
    {
        if (controller.Collisions.isRight || controller.Collisions.isLeft)
        {
            gameObject.SetActive(false);
        }

        controller.ApplyGravity(ref direction);

        if (controller.Collisions.isBelow)
        {
            controller.Bounce();
        }

        controller.ApplyMovement(direction);
    }
Example #3
0
 private void Update()
 {
     controller.ApplyGravity(ref direction, true);
 }
Example #4
0
    /// <summary>
    /// Maps player inputs into movement and calls appropriate commands from the controller.
    /// </summary>

    void MoveByInput()
    {
        // Get the current axis values and add them to a vector.
        FindAxes();

        UpdateFacingDirection(input);

        bool crouching;

        bool isJumping = false;

        if (Input.GetKey("s") || Input.GetKey("down"))
        {
            crouching = true;
        }
        else
        {
            crouching = false;
        }

        controller.Crouch(crouching);

        if (IsStill() && !SpacePressed())
        {
            // If we arent moving then just apply gravity normally.
            controller.ApplyGravity(ref input, true);

            animator.SetBool("isWalking", false);
        }
        else
        {
            controller.ApplyGravity(ref input);

            if (SpacePressed())
            {
                if (controller.Collisions.isBelow)
                {
                    controller.Jump(ref input);
                    SoundManager.instance.PlaySingle(jumpSound);
                }
            }

            if (controller.Collisions.isBelow && input.x != 0)
            {
                animator.SetBool("isWalking", true);
            }

            controller.ApplyMovement(input);
        }

        if (!controller.Collisions.isBelow)
        {
            isJumping = true;
        }

        animator.SetBool("isJumping", isJumping);



        // If anything is listening for player movement then invoke the delegate.
        if (playerMoved != null)
        {
            playerMoved.Invoke();
        }
    }