Search code examples
libgdxviewport

How to fix a touch point with camera fit viewport accurately?


FitViewport

when using this viewport and get the touch point, as you can see in the below 1st GIF that the bullet is direction is not accurate to the touch point.

fit viewport

StretchViewport

but using this viewport, the touch point and bullet direction is entirely fixed and accurate.

stretch viewport


Solution

  • If a Camera has a Viewport, use the viewport class method unproject() instead of using the camera class.