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: Code (CSharp): 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) Code (CSharp): 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 http://www.blueraja.com/blog/404/how-to-use-unity-3ds-linear-interpolation-vector3-lerp-correctly 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