My personal way is using a custom lerp. (clerp)
(Bit more advanced method)
local function clerp(p1,p2,percent)
local p1x,p1y,p1z,p1R00,p1R01,p1R02,p1R10,p1R11,p1R12,p1R20,p1R21,p1R22 = p1:components()
local p2x,p2y,p2z,p2R00,p2R01,p2R02,p2R10,p2R11,p2R12,p2R20,p2R21,p2R22 = p2:components()
return
CFrame.new(p1x+percent*(p2x-p1x), p1y+percent*(p2y-p1y) ,p1z+percent*(p2z-p1z),
(p1R00+percent*(p2R00-p1R00)), (p1R01+percent*(p2R01-p1R01)) ,(p1R02+percent*(p2R02-p1R02)),
(p1R10+percent*(p2R10-p1R10)), (p1R11+percent*(p2R11-p1R11)) , (p1R12+percent*(p2R12-p1R12)),
(p1R20+percent*(p2R20-p1R20)), (p1R21+percent*(p2R21-p1R21)) ,(p1R22+percent*(p2R22-p1R22)))
end
http://wiki.roblox.com/index.php?title=Magnitude
Example of my clerp.. (client)
local cam = workspace.CurrentCamera
local part1 = workspace.Part1
local char = workspace:WaitForChild(game.Players.LocalPlayer.Name)
local rs = game:GetService("RunService").RenderStepped
cam.CameraType="Scriptable"
for i = 1, ((part1.Position - char.Torso.Position).magnitude), 1 do
cam.CoordinateFrame = clerp(
cam.CoordinateFrame,
part1.CFrame
,.02)
rs:wait()
end
-- HOW MY CLERP WORKS --
It runs all off of CFrame, thus to change the camera position. (VERY smoothly)
http://wiki.roblox.com/index.php?title=CFrame
http://prntscr.com/ajzsh1
Lets use CoordinateFrame because it runs on CFrame.
camera.CoordinateFrame
Now, since my clerp returns a CFrame, we need to do this..
camera.CoordinateFrame = clerp( a, b, c )
The first arg of my clerp needs to be a CFrame, the CFrame we will be using
camera.CoordinateFrame = clerp( camera.CoordinateFrame , b, c )
The second arg of my clerp need to be the CFrame YOU WANT
camera.CoordinateFrame = clerp( a , CFrame.new(9,576,50) , c )
The last bit of my clerp (#arg 3) needs to be a decimal. Such as .01 - 1
This last arg will determine how quick the (and smooth) the movement will be
camera.CoordinateFrame = clerp( a , b , .02 )
I have already set up the correct camera interpolation decimal, but change it if you need. :)
5 comments
Inefficient :c
Not really, clerps are MUCH faster then normal lerp. Plus its just smoother. The for i loop I made quickly because Im on tablet lol
Least I took my own time and will into making a custom lerp.
So what's the difference between clerping all the constructors of a CFrame rather than doing it with just the X,Y,Z Coords and eulear angles?
With a clerp you can pick and choose perfect angles while getting the smoothest usage possible. X.Y.Z could be used I would guess, but not as smooth as a custom clerp.