Camera follow the player.. HELP

Hello everyone.

I need get that my camera follow my character always leaving a margin of height above the character. I want this event is active after to give a click.

An example to follow is the game of “Into the Circle”, when the player it’s launched, the camera follows the character always leaving a margin of height between the character and the camera.

See the video:

This is my code:

if (Input.GetMouseButtonDown (0)) {

// This does not give me the result I want
camera.transform.position = new Vector3 (0, player.transform.position.y / 2, -10);
}

}

Maybe something like (not tested)

float height = 5f;
float speed = .2f;
Vector3 targetCamPosition;

Void Start()
{
    targetCamPosition = camera.transform.position;
}

void Update()
{
    if (Input.GetMouseButtonDown (0))
    {
        targetCamPosition = camera.transform.position + (Vector3.up * height);
    }

    camera.transform.position = Vector3.Lerp(camera.transform.position, targetCamPosition, speed * Time.deltaTime);
}

People might comment on how the lerp I am doing is wrong, but it isnt, it just might not give the result you are expecting. You can look online for different ways to use lerp, such as here Using Vector3.Lerp() correctly in Unity — One Man's Trash is Another Man's Blog
Sorry if I misstyped something or the logic is wrong. Writing code on a tablet is painful.

@HiddenMonk Thank you very much for the reply. The code did not work as I want, but I managed to give me an idea and now works :slight_smile: