Release camera

Hello, I am developing a mobile video game and I want that when the player does not touch the screen, the camera always changes position behind the character.

The problem is that my character can rotate, that is, the coordinates of the back of my character always change and I don’t know how it calculates the distance between the camera and my character adjusting to the direction.


//heres the part of the code thah im working

//the camera is child of my character

        Vector3 desiredPosition = (target.position - offset);

        Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);

        transform.position = smoothedPosition;



That code works but doesnt look the back of my charcter because the constant of the offset.

transform.forward is probably what you need. (target.forward - offset)