Make camera follow and look at object at the same time
I need a camera that follows a player but also looks at the character as he/ she changes direction.
What I have is a character that changes direction relative to the camera's direction. When I press a left or right key, he/ she will rotate 90 degrees (or -90 degrees) from where the camera is facing. now I add the following code:
transform.LookAt(player.transform);
Now, when the character moves left or right, relative to the camera, the camera rotates. This causes the character to move in a circle around the camera while the camera is following (which is AWESOME).
Now all I need is for the camera to also follow the character in the forward direction of that character at the same time the camera is looking at the character.
The problem arises when I add THIS code to do that:
transform.position = Vector3.MoveTowards(transform.position, player.transform.position + distance, 10f);
Now the camera just follows the player but does not rotate. Can anybody help me?
and even if I only change the position for the z axis and rotate on the x and y axis', it still does not work right.
I think my current code is limiting. What I really want is a smooth way for the camera to move back behind the character as they change direction relative to the camera's position.
Your answer
Follow this Question
Related Questions
Maximum Camera Angle Rotation 0 Answers
Fixed Camera rotate to follow player 2 Answers
Way to rotate Camera with standart Vectors(forward,right, up) 0 Answers
Spyro Like Camera Follow 0 Answers