- Home /
How can I create multiple camera locations.
I'm working on a game which has vehicles, and each vehicle can have multiple camera locations. I would like to do something like the following:
Vehicle
CameraRig
FrontCamera
RearCamera
LeftCamera
RightCamera
Obviously enough this is my transform tree for the vehicle, each of FrontCamera, RearCamera, LeftCamera, and RightCamera have their own position & rotation for where I want the camera locations on the vehicle. To place the camera there I simply connect my MainCamera transform to whichever CameraRig node I like, using
MainCamera.parent = Vehicle.Find("CameraRig/" + CameraName);
This actually works fine, except in the camera the view doesn't change. This seems to be because MainCamera.position & MainCamera.rotation are being updated (automatically ??) for me as I change it's parent. If I re-set MainCamera.rotation and MainCamera.position to 0,0,0 after updating it's parent then the camera view shows the correct view (Front, Left, Right, Rear etc.).
My questions are :
Why does my MainCamera position & rotation change when I update it's parent ?
How can I stop it (without doing a MainCamera.position = after re-setting it's parent) ?
Is there a better established way of implementing multiple cameras ?
Any help very gratefully received.
Answer by Adamcbrz · Aug 06, 2013 at 04:45 AM
1) what you are seeing is the difference between local postion and world position. The world position doesn't change when you parent a transform but the local position is local to its parent.
2 ) I think you are out of luck on this one. I don't know a way around not resetting the position and rotation. But it's not that difficult if you use localPosition an localRotation. Just set them to zero and you match the parent.
transform.localPosition = Vector3.zero;
transform.localRotation = Quaternion.identity
3 ) this seems like a good approach. If you are not building for mobile and don't need to optimize you could have multiple cameras and just disable the ones you aren't using. But I think your current approach is best.
Thanks for the answer Adamcbrz
To be honest I expected that local geometry was the culprit, I think I just wanted to hear otherwise.
In fact I had the multiple camera approach done first, but I have multiple network players - each model with a CameraRig, the cams on all models get tagged $$anonymous$$ainCamera (even though they may be a remote player's model) now I'm adding more cam's to implement a radar & a remote view of a target. It's just too many cam's per model & I decided I needed to simplify.
I guess I'll just set localPosition & localRotation as I switch cameras, although it guves me an eye twitch to do it.
Thanks again.
Your answer
![](https://koobas.hobune.stream/wayback/20220613111616im_/https://answers.unity.com/themes/thub/images/avi.jpg)