Пример #1
0
    void FixedUpdate()
    {
        CurrentState.BeforeFixed();

        //React to input.

        if (MovementKeyAxes.x != 0)
        {
            CurrentState = CurrentState;
        }
        CurrentState.Sideways(MovementKeyAxes.x);

        if (MovementKeyAxes.y == 0.0f)
        {
            LockVerticalControls = false;
        }

        if (!LockVerticalControls && MovementKeyAxes.y > 0.0f)
        {
            CurrentState.Up();
        }

        if (!LockVerticalControls && MovementKeyAxes.y < 0.0f)
        {
            CurrentState.Down();
        }


        //Accelerate.

        Velocity            += (CurrentGravity + Propulsion) * Time.fixedDeltaTime / ActorProps.Mass;
        MostRecentPropulsion = Propulsion;
        Propulsion           = Vector3.zero;

        CurrentState.AfterAccel();


        //Constrain the velocity.

        CurrentState.BeforeConstrainVelocity();

        Velocity.z = 0;
        if (Mathf.Abs(Velocity.x) > PlayerProps.MaxSpeeds.x)
        {
            Velocity.x = Sign(Velocity.x, WorldConstants.MinMovementSpeed) * PlayerProps.MaxSpeeds.x;
        }
        if (Mathf.Abs(Velocity.y) > PlayerProps.MaxSpeeds.y)
        {
            Velocity.y = Sign(Velocity.y, WorldConstants.MinMovementSpeed) * PlayerProps.MaxSpeeds.y;
        }

        CurrentState.AfterConstrainVelocity();


        //Move.

        CurrentState.BeforeMove();

        Velocity = CurrentState.ApplyFriction(Velocity);

        Vector3 old = transform.position;

        //Set velocity to zero if it's too small.
        if (Velocity.magnitude < WorldConstants.MinMovementSpeed)
        {
            Velocity = Vector3.zero;
        }

        //Move.
        if (Velocity != Vector3.zero)
        {
            collided            = false;
            transform.position += Velocity * Time.fixedDeltaTime;
        }

        //Set the velocity to the displacement.
        if ((transform.position - old).magnitude / Time.fixedDeltaTime < WorldConstants.MinMovementSpeed)
        {
            Velocity = Vector3.zero;
        }
        if (!collided)
        {
            Velocity = (transform.position - old) / Time.fixedDeltaTime;
        }

        //Check for being outside the map.
        CheckOutside();

        //Finish up.

        CurrentState.AfterMove();

        ColManager.CheckWallBounds();

        CurrentState.AfterFixed();
    }