- Home /
Advanced smooth Camera transition
I need to combine Lerp + smooth transition (using DeltaTime) somehow to have a smooth camera transition: If i use Lerp only it transitions smoothly, but: - it takes a lot of time on the final steps (i need to do it faster, since camera controls are blocked while it moving) - if i do angle check (if the angle is small enough) there is a small jump in camera position. (It is small but noticable and it is not nice)
So i want: - transition camera using Lerp for like 80% of the path - transition camera at constant speed for the last 20% of the path How do i get the speed of a Lerp transition in a frame? (So that i can use it as a speed factor for constant rate transition)
Answer by robertbu · Jul 31, 2014 at 06:13 PM
Instead of using the non-traditional, eased version of Lerp(), use an easing function. If you search for 'easing functions' or 'Unity3d easing functions' you will find many posts. Here is one blog post by WhyDoIDoIt:
http://whydoidoit.com/2012/04/06/unity-curved-path-following-with-easing/
I'm away from my desk, but here is a bit of untested code that moves from point a to point b in a fixed amount of time with easing.
var moving : boolean = false;
function MoveTo(a : Vector3, b : Vector3, time : float) {
moving = true;
var timer : float = 0.0;
while (timer <= time) {
var t : float = 1.0 + Mathf.Pow((timer / time - 1.0), 3.0);
transform.position = Vectore3.Lerp(a, b, t);
t += Time.deltaTime;
yield;
}
transform.position = b;
moving = false;
}
Replace the 3.0 in the Mathf.Pow() with other values to adjust the curve. And there are many other easing functions (the calculation of 't') other than the one I've used here. Using the sine fuction between 0.0 and PI / 2.0 might look nice for what you are doing. And there are more complicated co-routines that allow easing for both starting and stopping. I'm not using 'moving' here, but it gives you a boolean to check to avoid spawning a new coroutine while the current one is executing (and there are other ways of solving this problem).
Your answer
Follow this Question
Related Questions
Move along grid where facing 1 Answer
Smooth Movement using transform for fixed movement amount? 0 Answers
Smooth movement using Rigidbody2d 3 Answers
3D Tile Lighting 1 Answer