Beispiel #1
0
    // handle move commands
    private void Move()
    {
        // dash, maybe it`s better to pull this out?
        float useV = maxV;

        if (skills[0].IsOn())         // dash
        {
            useV *= 1.5f;
        }

        // get ax and ay
        Vector2 axis = cmdHolder.GetAxisCmd();
        float   horizontal = axis.x, vertical = axis.y;

        // give force
        rb2D.AddForce(new Vector2(horizontal * A, vertical * A), ForceMode2D.Force);

        // limitation on speed
        if (rb2D.velocity.SqrMagnitude() > useV)
        {
            rb2D.velocity *= (useV / rb2D.velocity.SqrMagnitude());
        }

        // state detect
        if (rb2D.velocity.SqrMagnitude() == 0f)
        {
            state = STATE.NORMAL;
        }
        else
        {
            state = STATE.MOVING;
        }

        // end
    }