tag:blogger.com,1999:blog-5850361782112692029.post6012454350080829825..comments2016-06-04T03:40:03.345-07:00Comments on Learning Unity: Camera Follow Scripttheoriginalyetihttp://www.blogger.com/profile/05055239535770088354noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5850361782112692029.post-81909019232139892302013-10-30T03:06:16.996-07:002013-10-30T03:06:16.996-07:00Import Scripts from assets ...here you will find s...Import Scripts from assets ...here you will find smooth follow script in standard assets folder. I am copying the script here<br /><br />Just store your player as target and your add the script to your camera. you will see that your camera will follow the player rotation<br /><br />/* This camera smoothes out rotation around the y-axis and height. Horizontal Distance to the target is always fixed.<br /><br />There are many different ways to smooth the rotation but doing it this way gives you a lot of control over how the camera behaves.<br /><br />For every of those smoothed values we calculate the wanted value and the current value. Then we smooth it using the Lerp function. Then we apply the smoothed values to the transform's position. */<br /><br />// The target we are following var target : Transform; // The distance in the x-z plane to the target var distance = 10.0; // the height we want the camera to be above the target var height = 5.0; // How much we var heightDamping = 2.0; var rotationDamping = 3.0;<br /><br />// Place the script in the Camera-Control group in the component menu @script AddComponentMenu("Camera-Control/Smooth Follow")<br /><br />function LateUpdate () { // Early out if we don't have a target if (!target) return;<br /><br />// Calculate the current rotation angles<br />var wantedRotationAngle = target.eulerAngles.y;<br />var wantedHeight = target.position.y + height;<br /> <br />var currentRotationAngle = transform.eulerAngles.y;<br />var currentHeight = transform.position.y;<br /> <br />// Damp the rotation around the y-axis<br />currentRotationAngle = Mathf.LerpAngle (currentRotationAngle, wantedRotationAngle, rotationDamping * Time.deltaTime);<br /> <br />// Damp the height<br />currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);<br /> <br />// Convert the angle into a rotation<br />var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);<br /> <br />// Set the position of the camera on the x-z plane to:<br />// distance meters behind the target<br />transform.position = target.position;<br />transform.position -= currentRotation * Vector3.forward * distance;<br /> <br />// Set the height of the camera<br />transform.position.y = currentHeight;<br /> <br />// Always look at the target<br />transform.LookAt (target);<br />}Anonymoushttps://www.blogger.com/profile/07257206346380780753noreply@blogger.comtag:blogger.com,1999:blog-5850361782112692029.post-17402283923644465492013-05-15T11:10:40.353-07:002013-05-15T11:10:40.353-07:00I'm making a 3d game on third person view and ...I'm making a 3d game on third person view and was looking for a similar script. I tried using your script but it doesn't seem to work quite well.<br /><br />The camera starts facing the character, not behind it. Also, when I rotate the character the camera follows along too fast. <br /><br />Any ideas why this might be happening?israelhttps://www.blogger.com/profile/10760026480384030098noreply@blogger.com