// Update is called once per frame
    void Update()
    {
        Vector2 pos = gameObject.transform.position;

        //Save the last 3 positions
        lastPos3 = lastPos2;
        lastPos2 = lastPos;
        lastPos  = pos;

        //récupère la vitesse des différentes forces
        Vector2 speed = new Vector2(0, 0);

        speed += inputManager.getSpeedVector();
        speed += gravityManager.getSpeedVector();

        //Cas où l'on est en WallJump
        if (isWallJumping)
        {
            timerWallJumping += Time.deltaTime;
            if (timerWallJumping > timeWallJumpingLimit)
            {
                isWallJumping = false;
            }
            else
            {
                speed.x = vectorWallJumping.x * (timeWallJumpingLimit - timerWallJumping) / timeWallJumpingLimit
                          + speed.x * (timerWallJumping) / timeWallJumpingLimit;
            }
        }


        //On applique le facteur de vitesse quand on est sur le sol
        if (!isOnAir)
        {
            speed.x = speed.x * speedFloorFactor;
        }

        //Annulation des vitesses verticales si l'on est bloqué
        if (!canGoLeft && speed.x < 0)
        {
            speed.x = 0;
        }
        if (!canGoLeft && speed.x > 0)
        {
            if (collision.getNumberSurfaceContact() == 1)
            {
                waitForRight -= Time.deltaTime;
                if (waitForRight < 0)
                {
                    setCanGoLeft(true);
                }
                else
                {
                    speed.x = 0;
                }
            }
            else
            {
                setCanGoLeft(true);
            }
        }
        else
        {
            waitForRight = timeStickOnWall;
        }
        if (!canGoRight && speed.x > 0)
        {
            speed.x = 0;
        }
        if (!canGoRight && speed.x < 0)
        {
            if (collision.getNumberSurfaceContact() == 1)
            {
                waitForLeft -= Time.deltaTime;
                if (waitForLeft < 0)
                {
                    setCanGoRight(true);
                }
                else
                {
                    speed.x = 0;
                }
            }
            else
            {
                setCanGoRight(true);
            }
        }



        //Nouvelle position du cube
        pos      += speed * Time.deltaTime;
        lastSpeed = speed; // Save last speed
        gameObject.transform.position = pos;
    }