- Home /
Camera Smooth Distance Change
Hello!
I'd like my camera to move a bit further when the player triggers a turbo, but with this code it doesn't move smoothly - it just instantly changes the cameras position.
void FixedUpdate () {
if (CarTouchControls.turboOn == true) {
distance = 3.0f;
} else {
distance = 1.8f;
}
}
Answer by alok-kr-029 · May 06, 2015 at 09:11 AM
why dont you use lerp to move the camera smoothly ? http://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
something along the lines of:
$$anonymous$$athf.Lerp (distance, turboDistance * Time.deltaTime); ?
or you can even lerp your distance variable using $$anonymous$$athf.Lerp
if (CarTouchControls.turboOn == true) {
$$anonymous$$athf.Lerp (distance, turboDistance * Time.deltaTime);
} else {
$$anonymous$$athf.Lerp (turboDistance, distance * Time.deltaTime);
}
Gets the error: error CS1501: No overload for method Lerp' takes
2' arguments
You need to pass in three values as argument.
In first case:
distance
turboDistance
Time.deltaTime
Also you need to assign the output of $$anonymous$$athf.Lerp to your distance variable.
something like:
distance = $$anonymous$$athf.Lerp (distance, turboDistance, Time.deltaTime);
@Abacab there should be a comma between turboDistance and Time.deltaTime and not asterisk(*).
Your answer
![](https://koobas.hobune.stream/wayback/20220613194911im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Smooth Move script for my spaceship 0 Answers
Smooth Rotation 2 Answers
Map level selection slide smoothly 3 Answers
Need help/advice with 2D Camera follow script. 1 Answer
How can I get my camera to reset its position behind the player? 1 Answer