Question by
tgb20 · Oct 18, 2015 at 09:07 AM ·
camera-movementpositioningorthographic camerax-axisco-op
Make 2 Players Stay on Screen at Same Time
I am currently working on adding co-op to our game and the 2 players share a camera. I am trying to write a script that will allow the 2 players to be on the screen all the time. I have made a basic script that works for the X axis but if they ever end up on top of each other it breaks. Any ideas?
transform.position = new Vector3((player1.transform.position.x + player2.transform.position.x) * 0.5f, (player1.transform.position.y + player2.transform.position.y) * 0.5f, transform.position.z);
GetComponent<Camera>().orthographicSize = (player1.transform.position.x - player2.transform.position.x) * -1;
Comment