I’m new to Unreal Engine, and currently trying to adapt a project I had started in jMonkey a few years back. It’s a side-scroller with 3D elements (think Little Big Planet or the side-scroller levels in Crash Bandicoot) where the player is able to place and destroy blocks by clicking on the screen.
I’m using a perspective camera with a 90 degree FOV, and I’m splitting the viewport coordinates up so that the top-right corner on view port 1021x685 is (510.5, 342.5) and the bottom-left corner is (-510.5, -342.5) so when the player clicks on the screen it gets the coordinates from that range and adds it to the camera’s world space location. And that works… sort of.
In order for it to work correctly, I have to multiply the coordinates by an offset to get it to work correctly, but I don’t know how to get that. I played around with a few view port sizes and I know that for:
Viewport size 1021x685 I have to multiply by 0.33 (so *1.33)
Viewport size 547x647 I have to multiply by 1.5 (so *2.5)
Viewport size 528x350 I have to multiply by 1.55 (so *2.55)
Viewport size 282x341 I have to multiply by 3.8 (so *4.8)
My problem is I don’t know how to get those number without hard-coding them. I want to be able to calculate it so it works with whatever window size the player is using, but nothing I’ve tried works so far. At this point, I don’t even know what kind of math I should be looking at to figure this out.
This is what I’m using to get screen coordinates before adding it to the camera’s world space coordinates: