Exemplo n.º 1
0
    private void JoystickPress(Transform center, Transform button, int fingerIndex, ref bool stickMoving, ref Vector2 direction)
    {
        Vector2 delta    = new Vector2(center.localPosition.x, center.localPosition.y);
        Vector2 current  = handler.GetNowPos(fingerIndex);
        Vector2 target   = current;
        float   distance = (delta - current).sqrMagnitude;

        if (!stickMoving)
        {
            if (distance > JoystickGap * JoystickGap)
            {
                stickMoving = true;
            }

            Vector2 dir = delta - current;
            direction = -dir;
        }
        else
        {
            if (distance < JoystickGap * JoystickGap)
            {
                stickMoving = false;
            }

            float max       = JoystickGap * JoystickGap;
            float interpole = distance / max;
            target = delta - current;

            delta = Vector3.Lerp(delta, current + (target.normalized * JoystickGap), Ultimate.Time.globalDeltaTime * interpole * 10.0f);

            center.localPosition = Vector3.Lerp(center.localPosition, delta, 1.0f);

            direction = -target;
        }

        button.localPosition = Vector3.Lerp(button.localPosition, current, 1.0f);
    }