This camera script has three added lines of code to make the camera move as Player moves.
Attach this script to Following Camera in the Hierarchy panel:
An analysis of the code shown in the preceding screenshot is as follows:
Line 6: public float cameraHeight = 17.0f;
cameraHeight
stores the distance the camera will be above PlayerLine 7: public float cameraDistance = 17.0f;
cameraDistance
stores the distance the camera will be away from Player on the x and z axesLine 18: transform.position = playerPosition.position +
new Vector3(cameraDistance, cameraHeight, -cameraDistance);
playerPosition
stores the transform
data of Player, but all we want to know is the position
data from all that transform
dataplayerPosition.position
stores the constantly changing x, y, z position of PlayercameraHeight
and cameraDistance
can be added to the data of Player to specify where the camera should be locatedVec
tor3 x, y, z positions and added to the position of Player3.145.50.222