I have the following code so the camera follows the aircraft.
Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position, transform.position - transform.forward * 10f + transform.up * 2f, 5f * Time.deltaTime);
Camera.main.transform.rotation = Quaternion.Lerp(Camera.main.transform.rotation, transform.rotation, 5f * Time.deltaTime);
I want the camera to be slightly higher the aircraft so you don’t just see the back. That’s why there is an offset in the position. This is working fine, except now the camera is looking ‘over’ the aircraft, in stead of ‘at’. How do I make sure the camera looks at the aircraft, but still follows it’s rotation? Thanks
Still doesn't work.. When I add:
– boazlaurensCamera.main.transform.LookAt (transform.position);The camera doesn't rotate with the aircraft anymore when it rolls..Oh, I see, when it rolls too. Don't use LookAt, LookAt will make the camera face towards the aircraft from the position that it's in. What you want to do is move the camera to the position as described above, but match the aircraft's angle of rotation, like the code in your original post.
– nyongeYeah, but when I do that, the camera looks 'over' the aircraft in stead of 'at', because the camera is higher than the aircraft..
– boazlaurensGreat solution! Thank you so much! Have a nice day.
– boazlaurens