Rotate camera with point on object
I am going through the Junior Programmer pathway on Unity Learn and have come across an issue that isn't addressed in the provided solutions.
In the Camera Switcher bonus feature we are asked to introduce a first person camera on the front of the car. I have figured that out, but noticed that the camera doesn't rotate with the vehicle. So I set the camera rotation to match the car's rotation like this:
transform.rotation = player.transform.rotation;
which works, except it rotates in place around its own axis, so when turning 180 degrees the back of the car swings in front of the camera. Really what the desired behavior I think I want is for the camera to translate along with the front of the vehicle when the vehicle rotates.
I may be able to achieve this with some trigonometry, but I feel there is probably an easier way.
Is there already a solution for this?
Your answer
Follow this Question
Related Questions
How to make camera rotate spherically around an object 0 Answers
Rotate Camera around fixed point in specified increments (Bonus: How could I lerp this?) 0 Answers
Rotating Camera around Player's X-axis while rotating Player around its Y-axis (using mouse input) 0 Answers
FPS camera jitters while moving and turning 0 Answers
Rotation and translation between objects with TRS matrix 0 Answers