//We do everything movement related inside of a fixed update. This makes it so our game is very consistant. Having movement tied to an uncapped frame rate results in really bad things.
    //Right now for some reason our game fix updates at 50 frames a second. we will change that to 60 once I get less lazy.

    private void FixedUpdate()
    {
        if (movingRight)
        {
            //This is equal to 2 pixels every fixed update at 50 fps. If fps was at 60 it would be 120f to move 2 pix.
            _actor.SetHorizontalVeloicty(100f);
            //If we are 4 pixels away from our turning point we set moving right to false and start moving left
            if (transform.position.x > end.x)
            {
                movingRight = false;
            }
        }
        else
        {
            //Moving left
            _actor.SetHorizontalVeloicty(-100f);

            if (Vector2.Distance(transform.position, start) < 4f)
            {
                movingRight = true;
            }
        }
    }
Пример #2
0
    private void FixedUpdate()
    {
        bombThings();
        if (throwable.Thrown)
        {
            if (gameObject.layer == LayerMask.NameToLayer("Intangible") && !exploded)
            {
                adjustLayers();
            }

            bool isGoingRight = throwable.ThrowVelocity.x > 0;

            if (isGoingRight)
            {
                if (_actor._ControllerState.IsCollidingRight)
                {
                    throwable.ThrowVelocity = new Vector2(0, 0);
                }
            }
            else
            {
                if (_actor._ControllerState.IsCollidingLeft)
                {
                    throwable.ThrowVelocity = new Vector2(0, 0);
                }
            }

            if (_actor._ControllerState.IsCollidingDown)
            {
                throwable.ThrowVelocity = new Vector2(throwable.ThrowVelocity.x / 1.2f, 0);
                if (Mathf.Abs(throwable.ThrowVelocity.x) < 20)
                {
                    throwable.ThrowVelocity = new Vector2(0, 0);
                }
            }

            _actor.SetHorizontalVeloicty(throwable.ThrowVelocity.x);
        }
    }