- Home /
Using two cameras simultaneously in the same view
Sorry if something similar has been asked. I've done some searching and didn't find anything. I've had an issue for a while where if my player walks right up to a cube, a 3d model, etc and gets too close they'll see right through it. The standard fix has been to adjust my clipping planes down, but that never worked. (to the shock of everyone - myself included - who said that was the entirety of my issue.) Anyhow, a buddy of mine told me about a clever sounding trick that he had heard about, but never implemented, which I just tried with no success, but before giving up on it I thought I'd toss it to the community to see if it might be a viable option. Essentially, what it involves is making a second camera. (In my case I simply copy and pasted the main camera, changed the tag, allowed it only to see items tagged "building" in the culling mask and removed non - essential items, like the audio listener. I then enabled and activated that camera alongside my main camera, and it took over, so that the ONLY thing I saw were buildings. So I simply enabled it via script, and that meant that only the main camera was active. (so buildings didn't appear at all.) I'll be honest, I'm not married to this idea, and I can walk away from it, but just want to see if what has been suggested is possible. Thanks for your time / help, and God bless. :)
using UnityEngine;
using System.Collections;
public class MainMenuCameraSwitch : MonoBehaviour {
public Camera camera1;
public Camera camera2;
public Camera camera3;
bool camera1ActiveBool;
void Start () {
camera1.camera.active = true;
camera2.camera.active = false;
camera3.camera.active = false;
Time.timeScale = 0;
camera1ActiveBool = true;
}
void Update () {
//use whatever button you want to toggle
if(Input.GetButtonDown("Action")){
if (camera1ActiveBool == true)
{
camera1.camera.active = false;
camera2.camera.active = true;
camera3.camera.active = true;
Time.timeScale = 1;
camera2.enabled = true;
camera3.enabled = true;
camera1.enabled = false;
Destroy (this);
//camera1ActiveBool = false;
}
else if (camera1ActiveBool == false)
{
camera1.camera.active = true;
camera2.camera.active = false;
camera3.camera.active = false;
camera1ActiveBool = true;
}
}
}
}
Answer by foxter888 · Dec 11, 2013 at 08:32 AM
you where almost there trying to figure it out the main trick it's not tags it's actually layers, meaning you set the object you don't want to clip to have a certain layer and the second camera need to have it's Depth higher than the other camera, and set the clear flags setting to Depth only. besides making it on the mask part to only see that layer that you don't want it to clip through.
Hey foxter, thanks for that. Definitely helped me to see each layer properly. :)
Unfortunately, my problem still remains. I can still see through buildings, even with my clipping plain set way down. (that's no indication of the effectiveness of your answer, it just means that my theory didn't hold up)
You rock though, for getting me that far!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Third Person Camera Help? 0 Answers
move the object where camera look 0 Answers
UNITY 3D: How to make the camera follow the player? Smoothly 2 Answers