- Home /
How to create an old school camera switch when the player leaves/enters camera view
Hi
So i am fairly new to unity have been working on a small platforming game/demo. Now i have most of my animations and stuff like that working, but what i want is for locked off camera views, and another camera to activate when the player leaves the screen.
Like in the old platformer games like flashback/another world. So how do i go about doing this ? any help thanks in advance.
Answer by KellyThomas · Dec 22, 2013 at 05:37 PM
For your scenario I recommend moving you camera rather than having multiple cameras in the scene.
The simplest way is to calculate and apply the ideal camera position with an algorithm similar to this:
float screenWidth = 10.0f // viewable area in world units
Vector3 cameraPos = camera.transform.postion;
Vector3 playerPos = player.transform.postion;
cameraPos.x = screenWidth * (Mathf.RoundToInt(playerPos.x / screenWidth) + 0.5f);
camera.transform.postion = cameraPos;
If you want precise control of camera positions is suggest setting up gameobjects with:
a trigger collider; and
a child GameObject to act as a placeholder
a script so that on the
OnTriggerEnter
event it sets the camera position and rotation to match the child GameObject.
Then you need to set up enough of these so that the triggers cover the gameplay area, and the placeholders represent good camera angles.
Your answer
Follow this Question
Related Questions
How can I make a smooth camera transition over time with java script? 1 Answer
Need help for camera view like Air Strike 3d game ? 1 Answer
Is there any way to keep game object withing the limit of Camera FOV 3 Answers
How to make camera position relative to a specific target. 1 Answer
How to stop the camera from going out of bounds in a 2D platformer? 0 Answers