Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can someone explain Interpolate please?

Asked by
ItsMeKlc 235 Moderation Voter
8 years ago

Can someone please explain Interpolate() to me a little bit better? What is endPos? Where the camera ends? EndFocus?? Duration is how long it takes. right? http://wiki.roblox.com/index.php?title=API:Class/Camera/Interpolate

1 answer

Log in to vote
1
Answered by
EgoMoose 802 Moderation Voter
8 years ago

Interpolation is just a fancy way of saying tween which is short for in-between.

One simple way to do this is called a linear interpolation (LERP) and it works with both numbers and vectors. What it does is takes two points and based on some percentage travels across the length of the line created between them.

It's very easy to represent as a function:

function lerp(a, b, c)
    return a + (b - a) * c;
end;

As we can we're simple scaling the difference between b and a and then adding it back to a.

This process is the same for the position aspect of CFrames. The rotation however is done through something called a spherical linear interpolation (SLERP), but that requires knowledge of Quaternions which is not something I want to explain here b/c I don't want to type an essay.

If you are interested however I made a video: https://www.youtube.com/watch?v=BXajpAy5-UI

BE WARNED! Quaternions are not easy math and in Roblox you don't really need to know them b/c the built in methods will do the calculations for you. I only rcmd if you're really curious or really want to use quaternions to represent your rotations for some weird reason.

Anyways, Roblox does all this math on its own so there's no need to worry about how to calculate these values. What you need to know is that when you provide a start and end goal the interpolate method is going to transition from your camera's current position and current focus to the values you provided in a given time.

Ad

Answer this question