• Touch Camera
  • Unwanted behaviors appear when I changed the camera's viewport rect

Hi,

I just bought your assets and it was amazing! However, it started to create some unwanted behaviors when I changed the camera's viewport coordinate. In this case, I changed the X and Y to 0.5 respectively

The distance suddenly gets fixed to the minimum value, the scrolling function doesn't work properly anymore, etc. You can have a look a this video. Though maybe it is not very noticeable in the video, I hope you understand what the problem is.

My temporary measure is to hardcode the finalDistance to a certain fixed value because I don't understand how the calculations in CameraBase.cs works 😅. But it only solves one problem and doesn't fix the others. Do you have any solutions for this one?

Regards,
Gab.

    gabriabel Hi!

    Indeed the plugin is only supporting fullscreen cameras right now. The code is relying on screen coordinates, so if you change the viewport, then it won't work.
    You can try to edit lines relying on screen like these :
    Vector2 screenCenter = new Vector2(Screen.width * .5f, Screen.height * .5f);
    float aspect = (float)Screen.width / (float)Screen.height;

    Try to recalculate them to find the proper Camera screen center based on the viewport, and the new aspect ratio.

    If it's not enough, then the problem might go deeper into the input system with LeanTouch that also uses Screen calculations:
    HeightScreenDepth = new LeanScreenDepth(LeanScreenDepth.ConversionType.HeightIntercept, -5, groundHeight);

    I will have a look on my side in the next days to see if I can support that. Keep me posted if you find a solution in the mean time!

    Thanks 😉

      gabriabel Hi!
      So indeed you just have to replace the two lines I mentioned above to make it work.
      Replace the aspect lines by:
      float aspect = cam.aspect;
      And the screenCenter lines by:
      Vector2 screenCenter = cam.ViewportToScreenPoint(new Vector3(0.5f, 0.5f, 0));

      I will publish an update of the camera including this in the next days 😉

      Thanks for reporting.
      Anthony

      Awesome! Just tested it myself and it works like a charm. Turns out the solution is not as complicated as I thought haha😅

      Thanks for the support!

        Write a Reply...