Exemplo n.º 1
0
    private void Start()
    {
        playtime = 0;
        pData    = GetComponent <PlayerData>();
        if (File.Exists(selectedProfilePath))
        {
            selectedProfile = File.ReadAllText(selectedProfilePath);
            saveDataPath   += selectedProfile + ".json";
            if (File.Exists(saveDataPath))
            {
                string json = File.ReadAllText(saveDataPath);
                var    dto  = JsonConvert.DeserializeObject <PlayerDTO>(json);
                pData.serializeData = dto.playerSerializeData;
                playtime            = dto.Playtime;
                if (pData.HasCheckPoint)
                {
                    transform.position = new Vector2(pData.PosX, pData.PosY);
                }
            }
        }

        pInput         = new PlayerInput(pData);
        spriteRenderer = GetComponent <SpriteRenderer>();
        audioSource    = GetComponent <AudioSource>();

        #region Initialize States

        IdleState                    = new IdleState(this, pInput, pData, "Idle_Animation");
        RunningState                 = new RunningState(this, pInput, pData, "Running_Animation");
        FallingState                 = new FallingState(this, pInput, pData, "Falling_Animation");
        JumpState                    = new JumpState(this, pInput, pData, "Jump_Animation");
        StartFallingState            = new StartFallingState(this, pInput, pData, "Start_Falling_Animation");
        WallSlideState               = new WallSlideState(this, pInput, pData, "Wall_slide");
        DashingState                 = new DashingState(this, pInput, pData, "Dash_Animation");
        PrimaryAttackState           = new PrimaryAttackState(this, pInput, pData, "Left_swing_attack");
        GroundedSecondaryAttackState = new GroundedSecondaryAttackState(this, pInput, pData, "Right_swing_attack");
        GroundedDownwardAttackState  = new GroundedDownwardAttackState(this, pInput, pData, "Downward");;
        DeathState                   = new DeathState(this, pInput, pData, "Death_Animation");
        CheckPointState              = new CheckPointState(this, pInput, pData, "CheckPoint_Animation");
        WallJumpState                = new WallJumpState(this, pInput, pData, "Jump_Animation");

        currentState = IdleState;

        #endregion Initialize States
    }
Exemplo n.º 2
0
    public PlayerControllerData(PlayerController player)
    {
        Player               = player;
        PlayerRB             = Player.GetComponent <Rigidbody2D>();
        MainCollider         = Player.GetComponent <CapsuleCollider2D>();
        PlayerSpriteRenderer = Player.GetComponent <SpriteRenderer>();
        PlayerCam            = Camera.main;
        PlayerAnimator       = Player.GetComponent <Animator>();
        PlayerHUD            = GameObject.Find("HUD_Base_Panel").GetComponent <HUD>();
        PlayerBoomerang      = Player.GetComponentInChildren <BoomerangObj>();

        PlatformLayer = LayerMask.GetMask("World");

        Idle     = new IdleState(this);
        Movement = new MoveState(this);
        Jump     = new JumpState(this);
        InAir    = new InAirState(this);
        Aim      = new AimState(this);
        Throw    = new ThrowState(this);
        WallJump = new WallJumpState(this);
        SetState(Idle);

        AnimStates = new Dictionary <State, string>()
        {
            { Idle, idleAnim },
            { Movement, moveAnim },
            { Jump, idleAnim },
            { InAir, inAirAnim },
            { Aim, null },
            { Throw, null },
            { WallJump, onWallAnim }
        };

        maxPlayerHealth = 100.0f;
        playerHealth    = maxPlayerHealth;
        maxPlayerPotion = 50.0f;
        playerPotion    = maxPlayerPotion;
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        // Debug.Log(_controller.collisionState.ToString());
        if (isInvincible)
        {
            _invincibleTimer -= Time.deltaTime;
            if (_invincibleTimer <= 0)
            {
                isInvincible = false;
            }
        }

        if (_controller.isGrounded)
        {
            _usedAirDash = false;
            usedDoubleJump = false;
            _usedVairDash = false;
        }

        switch (state)
        {
            case State.IDLE:
                _releasedJump = false;
                _velocity.x = 0;

                if (!_controller.isGrounded)
                {
                    state = State.JUMPING;
                    _releasedJump = true;
                    break;
                }
                else
                {
                    _afterimages.StopImages();
                    if (Input.GetKey(KeyCode.DownArrow))
                    {
                        _velocity.y -= 3f;
                        _controller.ignoreOneWayPlatformsThisFrame = true;
                    }
                }

                if (Input.GetAxis("Horizontal") < 0 || Input.GetAxis("Horizontal") > 0)
                {
                    state = State.RUNNING;
                }

                if (Input.GetButtonDown("Jump"))
                {
                    if (_controller.isGrounded)
                    {
                        state = State.JUMPING;
                        StartJump(ref _velocity);
                    }
                }
                break;
            case State.RUNNING:
                _releasedJump = false;

                if (!_controller.isGrounded)
                {
                    state = State.JUMPING;
                    _releasedJump = true;
                    break;
                }
                else
                {
                    _afterimages.StopImages();
                    if (Input.GetKey(KeyCode.DownArrow))
                    {
                        _velocity.y -= 3f;
                        _controller.ignoreOneWayPlatformsThisFrame = true;
                    }
                }

                if (Input.GetAxis("Horizontal") < 0)
                {
                    _velocity.x = -1 * runSpeed;
                    if (transform.localScale.x > 0f)
                        transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                }
                else if (Input.GetAxis("Horizontal") > 0)
                {
                    _velocity.x = runSpeed;
                    if (transform.localScale.x < 0f)
                        transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                }
                else
                {
                    state = State.IDLE;
                    _velocity.x = 0;
                }

                if (Input.GetButtonDown("Dash"))
                {
                    state = State.DASHING;
                    StartDash();
                }

                if (Input.GetButtonDown("Jump"))
                {
                    state = State.JUMPING;
                    StartJump(ref _velocity);
                }

                break;

            case State.JUMPING:
                if (_controller.isGrounded)
                {
                    _afterimages.StopImages();
                    if (Input.GetKey(KeyCode.DownArrow))
                    {
                        _velocity.y -= 3f;
                        _controller.ignoreOneWayPlatformsThisFrame = true;
                    }
                }
                else
                {
                    if (Input.GetAxis("Vertical") < 0 && Input.GetButtonDown("Dash"))
                    {
                        state = State.DIVING;
                        StartDive();
                        break;
                    }
                }

                if (Input.GetAxis("Horizontal") < 0 )
                {
                    if (_wallJumpState == WallJumpState.LEFT)
                    {
                        _wallJumpState = WallJumpState.OFF;
                    }

                    if (_wallJumpState == WallJumpState.RIGHT && _temporaryWallJumpAccel > 0)
                    {
                        _velocity.x = _temporaryWallJumpAccel;
                        if (dashJump)
                        {
                            _temporaryWallJumpAccel -= (Time.deltaTime * wallDashJumpDecayRate);
                        }
                        else
                        {
                            _temporaryWallJumpAccel -= (Time.deltaTime * wallJumpDecayRate);
                        }
                    }
                    else if (dashJump)
                    {
                        _velocity.x = -dashSpeed;
                    }
                    else
                    {
                        _velocity.x = -runSpeed;
                    }

                    if (_controller.isGrounded)
                    {
                        state = State.RUNNING;
                        dashJump = false;
                        _wallJumpState = WallJumpState.OFF;
                    }

                    if (transform.localScale.x > 0f)
                        transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);

                    if (_controller.collisionState.left && _controller.velocity.y < 0)
                    {
                        state = State.WALLCLINGING;
                        break;
                    }

                }
                else if (Input.GetAxis("Horizontal") > 0 )
                {
                    if (_wallJumpState == WallJumpState.RIGHT)
                    {
                        _wallJumpState = WallJumpState.OFF;
                    }

                    if (_wallJumpState == WallJumpState.LEFT && _temporaryWallJumpAccel < 0)
                    {
                        _velocity.x = _temporaryWallJumpAccel;
                        if (dashJump)
                        {
                            _temporaryWallJumpAccel += (Time.deltaTime * wallDashJumpDecayRate);
                        }
                        else
                        {
                            _temporaryWallJumpAccel += (Time.deltaTime * wallJumpDecayRate);
                        }

                    }
                    else if (dashJump)
                    {
                        _velocity.x = dashSpeed;
                    }
                    else
                    {
                        _velocity.x = runSpeed;
                    }

                    if (_controller.isGrounded)
                    {
                        state = State.RUNNING;
                        dashJump = false;
                        _wallJumpState = WallJumpState.OFF;
                    }
                    if (transform.localScale.x < 0f)
                        transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    if (_controller.collisionState.right && _controller.velocity.y < 0)
                    {
                        state = State.WALLCLINGING;
                        break;
                    }
                }
                else
                {
                    _velocity.x = 0;
                    if (_controller.isGrounded)
                    {
                        state = State.IDLE;
                        dashJump = false;
                        _wallJumpState = WallJumpState.OFF;
                        break;
                    }
                }

                if (Input.GetAxis("Vertical") > 0 && Input.GetButtonDown("Dash") && !_usedVairDash)
                {
                    state = State.VAIRDASHING;
                    StartVairDash();
                    break;
                }

                if (Input.GetButtonDown("Dash") && !_usedAirDash)
                {
                    StartAirDash();
                    state = State.AIRDASHING;
                    break;
                }

                if (Input.GetButtonUp("Jump") && !_releasedJump && _controller.velocity.y > 0)
                {
                    _velocity.y = 0;
                    _releasedJump = true;
                    break;
                }

                if (Input.GetButtonDown("Jump") && !usedDoubleJump)
                {
                    StartJump(ref _velocity);
                    state = State.JUMPING;
                    usedDoubleJump = true;
                }

                break;

            case State.DASHING:
                _releasedJump = false;
                _dashTimer -= Time.deltaTime;

                if (!_controller.isGrounded)
                {
                    state = State.JUMPING;
                    _releasedJump = true;
                    dashJump = true;
                    break;
                }
                else
                {
                    if (Input.GetAxis("Vertical") > 0)
                    {
                        _velocity.y -= 3f;
                        _controller.ignoreOneWayPlatformsThisFrame = true;
                        dashJump = true;
                    }
                }

                bool releasedDash = false;

                if (_dashTimer < 0f)
                {
                    releasedDash = true;
                }

                if (Input.GetAxis("Horizontal") == 0 || Input.GetButtonUp("Dash"))
                {
                    releasedDash = true;
                    _dashTimer = dashTime;
                }

                if (Input.GetAxis("Horizontal") < 0)
                {
                    _velocity.x = -1 * dashSpeed;
                    if (transform.localScale.x > 0f)
                        transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    if (releasedDash)
                        state = State.RUNNING;
                }
                else if (Input.GetAxis("Horizontal") > 0)
                {
                    _velocity.x = dashSpeed;
                    if (transform.localScale.x < 0f)
                        transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
                    if (releasedDash)
                        state = State.RUNNING;
                }
                else
                {
                    state = State.IDLE;
                    _velocity.x = 0;
                }

                if (Input.GetButtonDown("Jump"))
                {
                    state = State.JUMPING;
                    dashJump = true;
                    StartJump(ref _velocity);
                }

                break;

            case State.DIVING:
                if (_controller.isGrounded)
                {
                    dashJump = false;
                    _disableGravity = false;
                    _afterimages.StopImages();
                    if (Input.GetAxis("Horizontal") > 0)
                    {
                        state = State.RUNNING;
                    }
                    else if (Input.GetAxis("Horizontal") < 0)
                    {
                        state = State.RUNNING;
                    }
                    else
                    {
                        state = State.IDLE;
                    }
                }

                if (Input.GetButtonDown("Jump") && !usedDoubleJump)
                {
                    state = State.JUMPING;
                    StartJump(ref _velocity);
                    usedDoubleJump = true;
                    _disableGravity = false;

                    if (!dashJump)
                    {
                        _afterimages.StopImages();
                    }

                }

                break;

            case State.AIRDASHING:
                _disableGravity = true;
                //_velocity.x = dashSpeed;
                _velocity.y = 0;

                _airDashTimer -= Time.deltaTime;

                bool releasedAirDash = false;

                if (_airDashTimer < 0f)
                {
                    releasedAirDash = true;
                }

                if (Input.GetButtonUp("Dash"))
                {
                    releasedAirDash = true;
                    _dashTimer = dashTime;
                }

                if (releasedAirDash)
                {
                    state = State.JUMPING;
                    _disableGravity = false;
                }

                if (Input.GetAxis("Vertical") < 0 && Input.GetButtonDown("Dash") && !_usedVairDash)
                {
                    state = State.VAIRDASHING;
                    StartVairDash();
                    break;
                }

                if (Input.GetAxis("Horizontal") > 0 && _controller.collisionState.right)
                {
                    state = State.WALLCLINGING;
                }
                else if (Input.GetAxis("Horizontal") < 0 && _controller.collisionState.left)
                {
                    state = State.WALLCLINGING;
                }

                break;

            case State.WALLCLINGING:
                dashJump = false;
                usedDoubleJump = false;
                _usedAirDash = false;
                _usedVairDash = false;
                _releasedJump = false;
                _velocity.y = wallSlideRate;
                _disableGravity = true;

                if (Input.GetAxis("Horizontal") < 0)
                {
                    _velocity.x = -runSpeed;
                }
                else if (Input.GetAxis("Horizontal") > 0)
                {
                    _velocity.x = runSpeed;
                }

                if (_controller.isGrounded)
                {
                    state = State.IDLE;
                    _disableGravity = false;
                    break;
                }

                if (!_controller.collisionState.right && !_controller.collisionState.left)
                {
                    state = State.JUMPING;
                    _disableGravity = false;
                    break;
                }

                if (_controller.collisionState.right)
                {
                    if (Input.GetAxis("Horizontal") <= 0)
                    {
                        state = State.JUMPING;
                        _disableGravity = false;
                        break;
                    }
                }
                else if (_controller.collisionState.left)
                {
                    if (Input.GetAxis("Horizontal") >= 0)
                    {
                        state = State.JUMPING;
                        _disableGravity = false;
                        break;
                    }

                }

                if (Input.GetButtonDown("Jump"))
                {
                    state = State.JUMPING;

                    if (Input.GetButton("Dash"))
                    {
                        dashJump = true;
                    }

                    if (_controller.collisionState.left)
                    {
                        if (!dashJump)
                        {
                            _temporaryWallJumpAccel = wallJumpX;
                            _afterimages.StopImages();
                        }
                        else
                        {
                            _temporaryWallJumpAccel = dashSpeed;
                            _afterimages.StartImages();
                        }
                        _wallJumpState = WallJumpState.RIGHT;
                    }
                    else if (_controller.collisionState.right)
                    {
                        if (!dashJump)
                        {
                            _temporaryWallJumpAccel = -wallJumpX;
                            _afterimages.StopImages();
                        }
                        else
                        {
                            _temporaryWallJumpAccel = -dashSpeed;
                            _afterimages.StartImages();
                        }
                        _wallJumpState = WallJumpState.LEFT;
                    }
                    _disableGravity = false;
                    StartJump(ref _velocity);
                    break;
                }
                break;
            case State.VAIRDASHING:
                _velocity.y = 0;
                _vairDashTimer -= Time.deltaTime;

                if (_vairDashTimer <= 0)
                {
                    state = State.JUMPING;
                    _velocity.y = vairDashSpeed;
                    _disableGravity = false;
                }

                if (Input.GetAxis("Horizontal") != 0 && Input.GetButtonDown("Dash") && !_usedAirDash)
                {
                    state = State.AIRDASHING;
                    StartAirDash();
                    break;
                }

                break;
            case State.HURT:
                _hurtTimer -= Time.deltaTime;
                _hurtKnockbackTimer -= Time.deltaTime;

                Quaternion rotate = Quaternion.Euler(new Vector3(0, 0, transform.rotation.eulerAngles.z + (1000 * Time.deltaTime)));

                transform.rotation = rotate;

                if (_hurtTimer <= 0)
                {
                    if (_controller.isGrounded)
                    {
                        if (Input.GetAxis("Horizontal") == 0)
                        {
                            state = State.IDLE;
                            StopHurt();
                            break;
                        }
                        else
                        {
                            state = State.RUNNING;
                            StopHurt();
                            break;
                        }
                    }
                    else
                    {
                        state = State.JUMPING;
                        StopHurt();
                        break;
                    }
                }

                if (_hurtKnockbackTimer > 0)
                {
                    _velocity.x = _hurtDistance;
                }
                else
                {
                    _velocity.x = 0;
                }

                break;
            default:
                break;

        }

        if (!_disableGravity)
        {
            _velocity.y += gravity * Time.deltaTime;
            if (_velocity.y < terminalVelocity)
            {
                _velocity.y = terminalVelocity;
            }
        }

        _velocity *= Time.deltaTime;
        _controller.move(_velocity);
        _velocity = _controller.velocity;
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        // Debug.Log(_controller.collisionState.ToString());

        _anim.SetFloat ("hSpeed", Mathf.Abs(Input.GetAxis("Horizontal")));

        if (_controller.isGrounded)
        {
            if (_controller.ground != null && _controller.ground.tag == "MovingPlatform") {
                this.transform.parent = _controller.ground.transform;
            } else {
                if (this.transform.parent != null) {
                    transform.parent = null;
                }
            }
            _usedAirDash = false;
            usedDoubleJump = false;
            _usedVairDash = false;
        }

        switch (state)
        {
            case State.IDLE:
                _releasedJump = false;
                _velocity.x = 0;

                if (!_controller.isGrounded)
                {
                    state = State.JUMPING;
                    _releasedJump = true;
                    break;
                }
                else
                {
                    //_afterimages.StopImages();
                    if (Input.GetKey(KeyCode.DownArrow))
                    {
                        _velocity.y -= 3f;
                        _controller.ignoreOneWayPlatformsThisFrame = true;
                    }
                }

                if (Input.GetAxis("Horizontal") < 0 || Input.GetAxis("Horizontal") > 0)
                {
                    state = State.RUNNING;
                }

                if (Input.GetButtonDown("Jump"))
                {
                    if (_controller.isGrounded)
                    {
                        state = State.JUMPING;
                        StartJump(ref _velocity);
                    }
                }
                break;
            case State.RUNNING:
                _releasedJump = false;

                if (!_controller.isGrounded)
                {
                    state = State.JUMPING;
                    _releasedJump = true;
                    break;
                }
                else
                {
                    //_afterimages.StopImages();
                    if (Input.GetKey(KeyCode.DownArrow))
                    {
                        _velocity.y -= 3f;
                        _controller.ignoreOneWayPlatformsThisFrame = true;
                    }
                }

                if (Input.GetAxis("Horizontal") < 0)
                {
                    _velocity.x = -1 * runSpeed;
                    if (transform.localScale.x > 0f){
                        Flip ();
                    }
                }
                else if (Input.GetAxis("Horizontal") > 0)
                {
                    _velocity.x = runSpeed;
                    if (transform.localScale.x < 0f) {
                        Flip ();
                    }
                }
                else
                {
                    state = State.IDLE;
                    _velocity.x = 0;
                }

                if (Input.GetButtonDown("Dash"))
                {
                    Debug.Log("dash");
                    state = State.DASHING;
                    StartDash();
                }

                if (Input.GetButtonDown("Jump"))
                {
                    state = State.JUMPING;
                    StartJump(ref _velocity);
                }

                break;

            case State.JUMPING:
                if (_controller.isGrounded)
                {
                    //_afterimages.StopImages();
                    if (Input.GetKey(KeyCode.DownArrow))
                    {
                        _velocity.y -= 3f;
                        _controller.ignoreOneWayPlatformsThisFrame = true;
                    }
                }
                else
                {
                    if (Input.GetAxis("Vertical") < 0 && Input.GetButtonDown("Dash"))
                    {
                        state = State.DIVING;
                        StartDive();
                        break;
                    }
                }

                if (Input.GetAxis("Horizontal") < 0 )
                {
                    if (_wallJumpState == WallJumpState.LEFT)
                    {
                        _wallJumpState = WallJumpState.OFF;
                    }

                    if (_wallJumpState == WallJumpState.RIGHT && _temporaryWallJumpAccel > 0)
                    {
                        _velocity.x = _temporaryWallJumpAccel;
                        if (dashJump)
                        {
                            _temporaryWallJumpAccel -= (Time.deltaTime * wallDashJumpDecayRate);
                        }
                        else
                        {
                            _temporaryWallJumpAccel -= (Time.deltaTime * wallJumpDecayRate);
                        }
                    }
                    else if (dashJump)
                    {
                        _velocity.x = -dashSpeed;
                    }
                    else
                    {
                        _velocity.x = -runSpeed;
                    }

                    if (_controller.isGrounded)
                    {
                        state = State.RUNNING;
                        dashJump = false;
                        _wallJumpState = WallJumpState.OFF;
                    }

                    if (transform.localScale.x > 0f)
                        Flip ();

                    if (_controller.collisionState.left && _controller.velocity.y < 0)
                    {
                        state = State.WALLCLINGING;
                        break;
                    }

                }
                else if (Input.GetAxis("Horizontal") > 0 )
                {
                    if (_wallJumpState == WallJumpState.RIGHT)
                    {
                        _wallJumpState = WallJumpState.OFF;
                    }

                    if (_wallJumpState == WallJumpState.LEFT && _temporaryWallJumpAccel < 0)
                    {
                        _velocity.x = _temporaryWallJumpAccel;
                        if (dashJump)
                        {
                            _temporaryWallJumpAccel += (Time.deltaTime * wallDashJumpDecayRate);
                        }
                        else
                        {
                            _temporaryWallJumpAccel += (Time.deltaTime * wallJumpDecayRate);
                        }

                    }
                    else if (dashJump)
                    {
                        _velocity.x = dashSpeed;
                    }
                    else
                    {
                        _velocity.x = runSpeed;
                    }

                    if (_controller.isGrounded)
                    {
                        state = State.RUNNING;
                        dashJump = false;
                        _wallJumpState = WallJumpState.OFF;
                    }
                    if (transform.localScale.x < 0f)
                        Flip ();
                    if (_controller.collisionState.right && _controller.velocity.y < 0)
                    {
                        state = State.WALLCLINGING;
                        break;
                    }
                }
                else
                {
                    _velocity.x = 0;
                    if (_controller.isGrounded)
                    {
                        state = State.IDLE;
                        dashJump = false;
                        _wallJumpState = WallJumpState.OFF;
                        break;
                    }
                }

                if (Input.GetAxis("Vertical") > 0 && Input.GetButtonDown("Dash") && !_usedVairDash)
                {
                    state = State.VAIRDASHING;
                    StartVairDash();
                    break;
                }

                if (Input.GetButtonDown("Dash") && !_usedAirDash)
                {
                    StartAirDash();
                    state = State.AIRDASHING;
                    break;
                }

                if (Input.GetButtonUp("Jump") && !_releasedJump && _controller.velocity.y > 0)
                {
                    _velocity.y = 0;
                    _releasedJump = true;
                    break;
                }

                if (Input.GetButtonDown("Jump") && !usedDoubleJump)
                {
                    StartJump(ref _velocity);
                    state = State.JUMPING;
                    usedDoubleJump = true;
                }

                break;

            case State.DASHING:
                _releasedJump = false;
                _dashTimer -= Time.deltaTime;

                if (!_controller.isGrounded)
                {
                    state = State.JUMPING;
                    _releasedJump = true;
                    dashJump = true;
                    break;
                }
                else
                {
                    if (Input.GetAxis("Vertical") > 0)
                    {
                        _velocity.y -= 3f;
                        _controller.ignoreOneWayPlatformsThisFrame = true;
                        dashJump = true;
                    }
                }

                bool releasedDash = false;

                if (_dashTimer < 0f)
                {
                    releasedDash = true;
                }

                if (Input.GetAxis("Horizontal") == 0 || Input.GetButtonUp("Dash"))
                {
                    releasedDash = true;
                    _dashTimer = dashTime;
                }

                if (Input.GetAxis("Horizontal") < 0)
                {
                    _velocity.x = -1 * dashSpeed;
                    if (transform.localScale.x > 0f)
                        Flip ();
                    if (releasedDash)
                        state = State.RUNNING;
                }
                else if (Input.GetAxis("Horizontal") > 0)
                {
                    _velocity.x = dashSpeed;
                    if (transform.localScale.x < 0f)
                        Flip ();
                    if (releasedDash)
                        state = State.RUNNING;
                }
                else
                {
                    state = State.IDLE;
                    _velocity.x = 0;
                }

                if (Input.GetButtonDown("Jump"))
                {
                    state = State.JUMPING;
                    dashJump = true;
                    StartJump(ref _velocity);
                }

                break;

            case State.DIVING:
                if (_controller.isGrounded)
                {
                    dashJump = false;
                    _disableGravity = false;
                    //_afterimages.StopImages();
                    if (Input.GetAxis("Horizontal") > 0)
                    {
                        state = State.RUNNING;
                    }
                    else if (Input.GetAxis("Horizontal") < 0)
                    {
                        state = State.RUNNING;
                    }
                    else
                    {
                        state = State.IDLE;
                    }
                }

                if (Input.GetButtonDown("Jump") && !usedDoubleJump)
                {
                    state = State.JUMPING;
                    StartJump(ref _velocity);
                    usedDoubleJump = true;
                    _disableGravity = false;

                    if (!dashJump)
                    {
                        //_afterimages.StopImages();
                    }

                }

                break;

            case State.AIRDASHING:
                _disableGravity = true;
                //_velocity.x = dashSpeed;
                _velocity.y = 0;

                _airDashTimer -= Time.deltaTime;

                bool releasedAirDash = false;

                if (_airDashTimer < 0f)
                {
                    releasedAirDash = true;
                }

                if (Input.GetButtonUp("Dash"))
                {
                    releasedAirDash = true;
                    _dashTimer = dashTime;
                }

                if (releasedAirDash)
                {
                    state = State.JUMPING;
                    _disableGravity = false;
                }

                if (Input.GetAxis("Vertical") < 0 && Input.GetButtonDown("Dash") && !_usedVairDash)
                {
                    state = State.VAIRDASHING;
                    StartVairDash();
                    break;
                }

                if (Input.GetAxis("Horizontal") > 0 && _controller.collisionState.right)
                {
                    state = State.WALLCLINGING;
                }
                else if (Input.GetAxis("Horizontal") < 0 && _controller.collisionState.left)
                {
                    state = State.WALLCLINGING;
                }

                break;

            case State.WALLCLINGING:
                dashJump = false;
                usedDoubleJump = false;
                _usedAirDash = false;
                _usedVairDash = false;
                _releasedJump = false;
                _velocity.y = wallSlideRate;
                _disableGravity = true;

                if (Input.GetAxis("Horizontal") < 0)
                {
                    _velocity.x = -runSpeed;
                }
                else if (Input.GetAxis("Horizontal") > 0)
                {
                    _velocity.x = runSpeed;
                }

                if (_controller.isGrounded)
                {
                    state = State.IDLE;
                    _disableGravity = false;
                    break;
                }

                if (!_controller.collisionState.right && !_controller.collisionState.left)
                {
                    state = State.JUMPING;
                    _disableGravity = false;
                    break;
                }

                if (_controller.collisionState.right)
                {
                    if (Input.GetAxis("Horizontal") <= 0)
                    {
                        state = State.JUMPING;
                        _disableGravity = false;
                        break;
                    }
                }
                else if (_controller.collisionState.left)
                {
                    if (Input.GetAxis("Horizontal") >= 0)
                    {
                        state = State.JUMPING;
                        _disableGravity = false;
                        break;
                    }

                }

                if (Input.GetButtonDown("Jump"))
                {
                    state = State.JUMPING;

                    if (Input.GetButton("Dash"))
                    {
                        dashJump = true;
                    }

                    if (_controller.collisionState.left)
                    {
                        if (!dashJump)
                        {
                            _temporaryWallJumpAccel = wallJumpX;
                            //_afterimages.StopImages();
                        }
                        else
                        {
                            _temporaryWallJumpAccel = dashSpeed;
                            //_afterimages.StartImages();
                        }
                        _wallJumpState = WallJumpState.RIGHT;
                    }
                    else if (_controller.collisionState.right)
                    {
                        if (!dashJump)
                        {
                            _temporaryWallJumpAccel = -wallJumpX;
                            //_afterimages.StopImages();
                        }
                        else
                        {
                            _temporaryWallJumpAccel = -dashSpeed;
                            //_afterimages.StartImages();
                        }
                        _wallJumpState = WallJumpState.LEFT;
                    }
                    _disableGravity = false;
                    StartJump(ref _velocity);
                    break;
                }
                break;
            case State.VAIRDASHING:
                _velocity.y = 0;
                _vairDashTimer -= Time.deltaTime;

                if (_vairDashTimer <= 0)
                {
                    state = State.JUMPING;
                    _velocity.y = vairDashSpeed;
                    _disableGravity = false;
                }

                if (Input.GetAxis("Horizontal") != 0 && Input.GetButtonDown("Dash") && !_usedAirDash)
                {
                    state = State.AIRDASHING;
                    StartAirDash();
                    break;
                }

                break;
            default:
                break;

        }

        if (!_disableGravity)
        {
            _velocity.y += gravity * Time.deltaTime;
            if (_velocity.y < terminalVelocity)
            {
                _velocity.y = terminalVelocity;
            }
        }

        _velocity *= Time.deltaTime;
        _controller.move(_velocity);
        _velocity = _controller.velocity;
    }
 private void resetWallJump()
 {
     lastJumpSide = WallJumpState.Free;
 }
    private bool WallJump()
    {
        // Ideas:
        // - Walljump height based on upwards velocity
        // - Walljump same side only once (reset per dash, other side hit, grounded, grab and/or possibly a timer)
        //

        bool fallDown = InputVertical < 0 || (InputVertical == 0 && InputHorizontal == 0);

        // Only walljump if it did not jump on that same side already
        WallJumpState jumpSideNow = facingRight ? WallJumpState.LastLeft : WallJumpState.LastRight;

        if (jumpSideNow == lastJumpSide && !fallDown) //Cancel out if trying to jump up
            return false;

        //Debug.Log(jumpSideNow + " " + lastJumpSide);

        lastJumpSide = jumpSideNow;

        // If jumping is allowed:
        // Handled as several cases:
        // - jump up when vertical input >= 0
        // - otherwise fall down

        float fr = WallSlideSettings.minSideVelocityFraction;
        float dir = facingRight ? -fr : fr;

        float hor = InputHorizontal;

        #region Fake analogue input when there is no analogue value

        if (InputVertical != 0 && !(Mathf.Abs(InputHorizontal) < 1.0f) && InputHorizontal != 0)
        {
            hor *= 0.5f;
            Debug.Log("WallJumpFraction");
        }
        #endregion

        // Only add the input fraction if the input is away from the wall (otherwise ignore)
        dir += Mathf.Sign(dir) == Mathf.Sign(hor) ? hor * (1 - fr) : 0;

        // Add the velocity
        rigid.velocity = new Vector2(RunSettings.RunMaxVelocity * dir, 0);

        // Fall
        if (fallDown)
            Fall();
        else
            Jump();

        // Double check the direction
        CheckFlipByVelocity();

        return true;
    }