- Home /
possible to set rotation of camera viewport?
one of my favourite games on tablets is a FPS called Neon Shadow. Anyway it has the option on tablets to be able to play 2 player splitscreen co op and deathmatch with each player controling a character on each end of the tablet. Is it possible to replicate that same splitcreen camera setup in unity buy rotating the camera’s viewport ?
Answer by Hellium · Mar 26, 2018 at 01:11 PM
1. Create two cameras
2. Call the first one "Left" or "Player1Camera".
a) Set rotation on the Z axis to 90°
b) Set viewport rect to (0, 0, 0.5, 0 )
3. Call the 2nd camera "Right" or "Player2Camera".
a) Set rotation on the Z axis to -90°
b) Set viewport rect to (0.5, 0, 0.5, 0 )
When creating the UI of the players, don't forget to set the Canvas to Screen space - camera
and drag & drop the appropriate player's camera.
that sounds easy enough, but isn’t that z rotation effecting the camera’s transform component and view the player gun holder at the wrong angle ?
$$anonymous$$mh, yes you are right.
I guess you will have to keep the Z rotation to 0, and change the Projection $$anonymous$$atrix of the camera ins$$anonymous$$d.
I don't have Unity right now, so I can't create you the appropriate code.
Try this:
public Camera Player1Camera ;
public Camera Player2Camera ;
private void Start()
{
Quaternion rotation ;
rotation = Quaternion.Euler( 0, 0, 89.9f ) ; // Don't put 90, or you will have a strange result
Player1Camera.projection$$anonymous$$atrix = $$anonymous$$atrix4x4.Rotate(rotation) * Player1Camera.projection$$anonymous$$atrix;
// OR
// Player1Camera.projection$$anonymous$$atrix = Player1Camera.projection$$anonymous$$atrix * $$anonymous$$atrix4x4.Rotate(rotation);
rotation = Quaternion.Euler( 0, 0, -89.9f ) ; // Don't put -90
Player2Camera.projection$$anonymous$$atrix = $$anonymous$$atrix4x4.Rotate(rotation) * Player2Camera.projection$$anonymous$$atrix;
// OR
// Player2Camera.projection$$anonymous$$atrix = Player2Camera.projection$$anonymous$$atrix * $$anonymous$$atrix4x4.Rotate(rotation);
}
that’s fine dude, I’m not expecting anything to big. I’ll try this and see if it works