- Home /
Shift camera viewport
Hello,
I am looking for a way to shift the camera viewport with a full screen width rendering.
Because I have a asymmetrical graphical user interface, I want my camera to render a little bit to the left.
Currently, I have set the viewport of my camera as follow : (X : 0, Y : 0, W : 0.875, H : 1)
. My camera renders a little bit to the left as I want, but, the camera does not render to my entire screen.
(Don't mind the interface, it's just here to help explaining what I have)
I have tried to set the width to a value greater than 1 and the X
value lower than 0 in order to render on all my screen and keep the shifting , but as soon as X + W >= 1
, the shifting does not work anymore.
One of my requirements is that the object must be perfectly aligned with the forward
vector of my camera. Think about a 3rd player game where the camera and the character are perfectly aligned.
I don't understand what you want to accomplish. Could you elaborate a bit more? I thought of leaving the viewport rect untouched (x,y:0, w,h:1) and have the camera rotate a bit to the right so your cube goes in the middle of your "1" and "0" ins$$anonymous$$d of middle of screen. Is there a reason of this idea not being viable?
Supposing you are playing a 3rd player game, your camera and your character are perfectly aligned. The idea is the same here.
This sounds like a bad idea, but what if you added a 2nd camera (rotated accordingly as I mentioned previously), child of you main one, so it can complement the right side. There will be overlay of the 2 cameras in the middle of the screen but if rotated precisely the user shouldn't see the difference I believe. You still have your forward vector aligned with the cube and the right side is covered.
Answer by Bunny83 · Oct 10, 2017 at 03:02 PM
You just want to use an off-center projection matrix. Unity actually has an example on the projectionMatrix documentation page. It's the second example.
Others have already turned it into a component which you can simply add to the camera. It requires an empty gameobject to specify the center of the "virual window". I never tried this script but it looks like it could work.
I should have thought about projection matrix.... Thanks a lot Bunny83 ! I will tweak a little bit the script so as to keep the "fieldOfView" property of the camera.
Answer by FortisVenaliter · Oct 09, 2017 at 06:46 PM
In the past, I've always found this easier to do after the fact. Render from your camera to a rendertexture, and apply that in 2D to the location on screen you want.
I will give the RenderTexture a try ;)
I will try to render to a texture bigger than the screen so that the texture will take the whole screen while being a little bit shifted.
Thanks for the advice, take this "+1" ! :)
Your answer
Follow this Question
Related Questions
Crosshair Not Parallel To camera 1 Answer
align the buttom of the viewport to the buttom of an object? 1 Answer
Camera picture stretching when width changed in script? 1 Answer
Why Is My Orthographic Camera Not Rendering at the Full Resolution? 1 Answer
Adjust Viewport Locations When Going to Full Screen -1 Answers