0
votes

I am building a horse racing game in Unity3D, I have problem with camera: Currently, my camera only focuses on one fixed horse (ex, horse No 1), so it causes when this horse is far away from others then there will be only one horse appeared on screen, it is not good solution. Anybody has some ideas on this? Thanks,

1
Many questions here regarding this, but this isn't really a programming question. You are asking for logic on how to implement this camera system. You need to come up with the rules you want, then you try to implement the code. Only at that stage can we try to help you, if you are having problems. There may be better, alternative, places to ask this question as it is, like gamedev.stackexchange.comanothershrubery
Naive solution for a single camera: find the bounding box of all the horses, point the camera at the middle of that box, and adjust the zoom so that all the horses are visible.RichieHindle
Thanks for all, Hello RichieHindle, Could you teach me that how can I find a bounding of all the horses?Bruce Vo
@BruceVo: Not here in a comment, no. :-) It's a well-defined concept - go and search for it.RichieHindle
@RichieHindle: Thanks so much, I will find out for this.Bruce Vo

1 Answers

1
votes

You can think as you were making a movie: just place more cameras on the scene, and activate them one at a time. If you want a camera per horse, you could place a camera directly into the horse's prefab (assuming you have it), so that each newly instantiated horse has one of them. Then, you can write a function that permits the cameras' switch:

var cameras : GameObject[];

function SelectCamera (index : int) {
    for (var i : int = 0; i < cameras.length; i++) {
        if (i == index){
            cameras[i].camera.active = true;
        }else{
            cameras[i].camera.active = false;
        }   
    }
}