- Home /
UNITY 3D: How to make the camera follow the player? Smoothly
So I have been trying to find way to make my camera movement like shown in the video, the video is from game rotacube (that's a good game). What I want to do is I want same action to happen that when I tap on screen the camera move along with my player and continually tapping makes it go faster. Also you can see on the video how camera is kind of delaying relative to the cube I just want to achieve this whole thing. I am kinda begginger, what I did was I literally duplicated and attached the camera and made it a child of my prefab game object so it looks like I don't know how to explain but it moves exactly as the player so it doesn't look so much smooth you know like how smooth it is in video. Sorry if I said anything wrong. Also if anyone can help. I would really appreciate. [Video] https://drive.google.com/file/d/1WzvsY47RZgmiGuoY1pe6l1_U19EeP2To/view?usp=drivesdk
Answer by lodendsg · Jul 14, 2020 at 01:24 PM
I strongly suggest using Cinemachine https://unity.com/unity/features/editor/art-and-design/cinemachine
You can install it from package manager, then simply create a vCam and set it to target you character and follow your character.
Cinemachine is incredibly powerful you can create complex orbital cameras, cameras that dolly while keeping multiple targets in frame, etc. all with zero code and runs very efficiently in my exp.
Thank you so so much, I did it but I had to make even cinemachine virtual cam a child of my prefab to work correctly but the motion of this cam is very smooth thanks. Also what can I do to make my character just go fast on continually tapping the screen. Thanks again
Answer by tuinal · Jul 14, 2020 at 02:12 PM
The quick 1-line code in Update or LateUpdate for a smooth motion is to replace e.g:
camera.position = myTargetPosition
With
camera.position = Vector3.Lerp(camera.position, myTargetPosition, Time.deltatime*cameraSpeed)
All Lerp does is interpolate between 2 points, however since you're updating the camera's position per-frame, the start point of the Lerp moves, resulting in smooth movement. The higher cameraSpeed is the faster the camera will move.
Thanks for your help also, but I think as a beginner I prefer cinemachine :) Btw if you can help in this i would really appreciate it, how can I increase the speed on continually tapping the screen.
Your answer
Follow this Question
Related Questions
Making a bubble level (not a game but work tool) 1 Answer
3D / Top-Down - Make a script to let the player zoom the camera in and out 0 Answers
Moving player in direciton camera is facing 1 Answer
Keeping an object constrained to a 2d radius based off of the camera 0 Answers
C# Twitchy Camera Movement 1 Answer