Beispiel #1
0
    private void Update()
    {
        actions["moveLeft"]  = _input.GetKey(InputKey.Left);
        actions["moveRight"] = _input.GetKey(InputKey.Right);

        if (_input.GetKeyDown(InputKey.Jump))
        {
            Jump();
        }

        if (!grounded && _input.GetKeyDown(InputKey.FastFall))
        {
            actions["fastfall"] = true;
        }
        else if (_input.GetKeyUp(InputKey.FastFall))
        {
            actions["fastfall"] = false;
        }

        if (curDashCooldown <= 0 && _input.GetKeyDown(InputKey.Dash))
        {
            curDashCooldown = dashCooldown;
            if (facing > 0)
            {
                myBody.velocity = new Vector2(0, myBody.velocity.y);
                myBody.AddForce(new Vector2(dashSpeed, 0), ForceMode2D.Impulse);
            }
            else
            {
                myBody.velocity = new Vector2(0, myBody.velocity.y);
                myBody.AddForce(new Vector2(-dashSpeed, 0), ForceMode2D.Impulse);
            }
        }

        if (curDashCooldown > 0)
        {
            curDashCooldown -= Time.deltaTime;
        }

        _animator.SetBool("isRunning", actions["moveLeft"] || actions["moveRight"]);
    }
Beispiel #2
0
    private void Update()
    {
        aMoveLeft  = _input.GetKey(InputKey.Left);
        aMoveRight = _input.GetKey(InputKey.Right);

        if (_input.GetKeyDown(InputKey.Jump))
        {
            Jump();
        }

        if (!grounded && _input.GetKeyDown(InputKey.FastFall))
        {
            aFastfall = true;
        }
        else if (_input.GetKeyUp(InputKey.FastFall))
        {
            aFastfall = false;
        }

        if (curDashCooldown <= 0 && _input.GetKeyDown(InputKey.Dash))
        {
            curDashCooldown = dashCooldown;
            if (facing > 0)
            {
                myBody.velocity = new Vector2(0, myBody.velocity.y);
                myBody.AddForce(new Vector2(dashSpeed, 0), ForceMode2D.Impulse);
            }
            else
            {
                myBody.velocity = new Vector2(0, myBody.velocity.y);
                myBody.AddForce(new Vector2(-dashSpeed, 0), ForceMode2D.Impulse);
            }
        }

        if (curDashCooldown > 0)
        {
            curDashCooldown -= Time.deltaTime;
        }


        //RaycastHit2D hit = Physics2D.Raycast(gameObject.transform.position, Vector2.down, 1.2f, 1 << floorMask);
        //Debug.DrawRay(transform.position, Vector2.down * 1.2f, Color.red, 1f);
        //if (hit.collider != null)
        //{
        //    Debug.Log(hit.collider.gameObject);
        //    grounded = true;
        //    jumps = maxAirJumps;
        //}
        //else
        //{
        //    RaycastHit2D hitRight = Physics2D.Raycast(gameObject.transform.position, Vector2.right, 5f, 1 << floorMask);
        //    RaycastHit2D hitLeft = Physics2D.Raycast(gameObject.transform.position, Vector2.left, 5f, 1 << floorMask);
        //    if (hitRight.collider != null)
        //        againstWallR = true;
        //    if (hitLeft.collider != null)
        //        againstWallL = true;

        //}

        //_animator.SetBool("isRunning", aMoveLeft || aMoveRight);
    }