How To Make Camera Follow Player Unity
In this tutorial, we will see polish camera follow in unity 3d. It is required when you desire the photographic camera to follow the player game object in the game.
For smoothen camera motility, we will use following points:
- Move player object in Update
- Move photographic camera object in LateUpdate
- Utilize SmoothDamp method for photographic camera movement. This provides ameliorate smoothness as compared with LERP method.
Utilise beneath script for smooth photographic camera movement and to follow the player object.
1 2 3 4 v 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | using UnityEngine ; public grade CameraFollow : MonoBehaviour { // camera will follow this object public Transform Target ; //photographic camera transform public Transform camTransform ; // commencement betwixt camera and target public Vector3 Offset ; // alter this value to get desired smoothness public float SmoothTime = 0.3f ; // This value will alter at the runtime depending on target motility. Initialize with nada vector. private Vector3 velocity = Vector3 . aught ; private void Outset ( ) { Offset = camTransform . position - Target . position ; } private void LateUpdate ( ) { // update position Vector3 targetPosition = Target . position + Showtime ; camTransform . position = Vector3 . SmoothDamp ( transform . position , targetPosition , ref velocity , SmoothTime ) ; // update rotation transform . LookAt ( Target ) ; } } |
Outcome
To know nigh LERP method, checkout my translate game objects blog.
Hope you get an thought about smooth camera post-obit in unity 3D. Mail your comments for queries and feedback. Thanks for reading.
The following two tabs change content below.
- Bio
- Latest Posts
Gyanendu Shekhar is a engineering science enthusiast. He loves to larn new technologies. His area of involvement includes Microsoft technologies, Augmented reality, Virtual reality, unity3d and android development.
Source: http://gyanendushekhar.com/2020/03/10/smooth-camera-follow-in-unity-3d/
Posted by: merlinawayet1963.blogspot.com
0 Response to "How To Make Camera Follow Player Unity"
Post a Comment