Camera Follow Position and Rotation
I want to write follow camera script for player's position and rotation both. At present I can able to write script so that it can follow player's position but can't able to write proper code for its rotation.
void Update ()
{
if (target == null)
return;
Vector3 targetCamPos = target.position + offset;
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
transform.LookAt (target);
// Vector3 targetCamRot = target.eulerAngles + offsetRot;
// transform.eulerAngles = Vector3.Lerp (transform.eulerAngles, targetCamRot, smoothing * Time.deltaTime);
}
I have used two approaches above but none of them worked for me.
In LookAt, I can't able to set my desire rotation of camera.
In EulerAngles camera get rotated its own place rather than related its target.
If I put my camera object inside player's child then its working properly, through this way I can able to get position and rotation change according to the player. But I want to do this through code rather than placing my camera under player game object.
Here is my game play over view:
Your answer
Follow this Question
Related Questions
I build a own game but i have a cam problem 0 Answers
Does anyone know the script for a smooth camera follow of the main game object? 8 Answers
Why is my camera shaking when I use my chaser script on something? 0 Answers
CAMERAS ERROR , I NEED HELP 0 Answers
Need Help With Having Player look at an object while stationary. 0 Answers