- Home /
How to Make the SmoothFollow Script Follow Faster?
As it is, the SmoothFollow.js works pretty good. However, I need it to follow my target faster when they are falling. The player gets away from the camera too fast and is too small on the screen.
How can we make the camera follow the target faster?
Any help is really appreciated.
Thanks!
Answer by robertbu · May 02, 2013 at 04:13 AM
Have you tried changing heightDamping value in the Inspector? A larger value should cause the camera to react faster.
Note the line of code that handles the smooth motion is this one:
currentHeight = Mathf.Lerp (currentHeight, wantedHeight, heightDamping * Time.deltaTime);
You can replace the Mathf.Lerp with Mathf.MoveTowards() to get a more linear movement (no easing at the end).
Yeah, I've tried that. Anything past 4 or 5 and the camera vibrates and shakes. I'll check out the $$anonymous$$athf.$$anonymous$$oveTowards() approach.
Thanks.
Another thing you could do is leave the damping code alone and put a limit on the max difference in height between the target and the camera. Add this towards the top of FixedUpdate() in the SmoothFollow script:
if ((transform.position.y - target.position.y) > maxHeightDiff)
transform.position.y = target.position.y + maxHeightDiff;
'maxHeightDiff' should be declared at the top of the file and be initialized to a value larger than 'height'.
Your answer
Follow this Question
Related Questions
[Closed] SmoothFollow trouble 0 Answers
Smooth Camera 2D 0 Answers
How do I make a camera look for a specific GameObject while networking? 1 Answer
Making a camera that follows a rigidbodied sphere. 2 Answers
Smooth Camera 2D Follow Player 0 Answers