Turning the camera down smoothly while running

How can I turn the camera down smoothly for xx degrees while running and returns to his original state while walking?

I only need the script for moving the camera down and up, can someone give me an example?

A very easy way to do this:

  1. Create an empty game object called “LookTarget” as a child of your character

  2. In your camera script, have the camera look at LookTarget every frame:

    Transform lookTarget = GameObject.Find(“LookTarget”).transform; //put this in Start()

    transform.LookAt(lookTarget); //put this in Update()

  3. In your character script, move LoookTarget according to character state… you can do simple vertical moves on the Y axis and the camera will automatically track.

This method has the advantage of letting you get the behavior you want without dealing with rotations directly, which can be complex.

As an optimization, you may want to assign lookTarget in the inspector instead of using GameObject.Find.

You can do it with animations which work well as they interpolate if the timescale is lowered. Add an empty gameobject between the camera and the player and animate it rotating down slightly and then back to 0,0,0 rotation. You’ll be able to control it normally but it will also be pulled down. This is what I did for left and right footsteps, it looks nice and this sample code should give you an idea.

if(moving == true){
    if(left == true){
        if(!anim.isPlaying){
	    anim.Play("walkLeft");
	    right = true;
	    left = false;
	    }
    }
    if(right == true){
        if(!anim.isPlaying){
	    anim.Play("walkRight");	
	    left = true;
	    right = false;
	    }
    }
}

If you just want it going up and down, in Update() just do something like this:

if(moving == true){
    if(!anim.IsPlaying){
        anim.Play("lowerCamera");
    }
}