Animation vs For loops ..

Hi all, what do you think fits better in this next case ? :

I player in third person controller, when the player runs, the camera´s fov increases to 70, … when the player walks the camera´s fov return to 50… i want to fade that… i have two ways (or at least i know) to make this :

In the animation window trace an animation curve of the camera´s fov from 50 to 70, and name it “increase_fov”
and create another animation curve from 70 to 50 and name it “decrease_fov”

then, according to the magnitude of the controller velocity, the animations crossfades between them.

the other way i have in mind is with For loops :

var cam : Camera;

function TheFOV (mode: String) {
if (mode == increase){
     for (var a : int = 50; a <=70; a++){
          cam.fieldOfView = a;
          yield WaitForSeconds(.2f);
          }

else if (mode == decrease){
     for (var b : int = 70; a >= 50; a--){
          cam.fieldOfView = b;
          yield WaitForSeconds(.2f);
          }
}

In performance, what´s better?

thanks.

Profile it and see!

For camera stuff I usually have one or two layers of smoothing using lerp/smoothstep and animation curve properties. Performance for stuff like this is generally a non-issue, you only have one camera in the scene, chances are there’s hundreds of other elements in the game that require much more thought in terms of performance/optimisation then a single camera script.

Your for loop there will make a stuttery transition, as it only updates the FOV 5 times a second. Using two animations that don’t actually animate and crossfading between them is a fair bit of overhead for something as simple as this.

I’d add a script to the camera which sets the FOV in Update() based on the player’s velocity. Alternatively, give the player’s current script a reference to the camera and do it there. Something like…

camera.fov = Mathf.Lerp(50, 70, lerpFactor);

… where lerpFactor is where you want it between the two given figures.

As Cameron says, though, performance for this kind of thing isn’t really an issue.

Allright mates, i will try Mathf, thanks!