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

Camera Circle Interpolation?

Asked by 11 years ago

So I made this script and it does work to a certain degree. The goal is to spin around an object and rise straight up still facing the nub of the circle. It is really blocky thought and not smooth. When the camera interpolates, it does not keep it's focus on the nub but rather the focus moves right with the camera as it interpolates.

Essentially it's really simple. It creates the position around the origin. Rises straight up. Finds the angle around the circle. Pushes the position to the circumference of the circle. Finds the nub of the circle at that height. Interpolate.

--module script

01function bod.SpinRise(cam, rise, origin, radius, wai)
02    local spin = 1440/rise
03    local ti = rise/wai
04    for i = 1,rise do
05        local cf = (origin * CFrame.new(0,i,0))
06                * CFrame.Angles(0,math.rad(spin*i),0)
07                * CFrame.new(0,0,-radius)
08        local look = origin * CFrame.new(0,i,0)
09        cam:Interpolate(cf,look,ti)
10        wait(ti)
11    end
12end

--Local script

1local camlib = require(game.Workspace.CameraLibrary)
2local cam = game.Workspace.CurrentCamera
3local orig = CFrame.new(0,0,0)
4cam.CameraType = "Scriptable"
5 
6camlib.SpinRise(cam,100,orig,50,60)

It does work but it's a very choppy. What can I do to make it smooth?

1 answer

Log in to vote
1
Answered by 11 years ago

Right, this is what I got. Seems to work in similar fashion, but it might not be the exact same behaviour, as it was hard to figure out all things that you were doing there + I don't really like the roblox's interpolate method in this case. Well right, this is as smooth as it gets:

01function bod.SpinRise(cam, rise, origin, radius, wai)
02    local spin = 1440/rise
03    local i = 0
04    local lastTick = tick()
05    while i<rise do
06        rs.RenderStepped:wait()
07        local dt = tick()-lastTick
08 
09        i = i+(rise/wai)*dt
10 
11        local cf = CFrame.new(origin.p + Vector3.new(math.cos(math.rad(i*spin)), 0, math.sin(math.rad(i*spin)))*radius + Vector3.new(0, i, 0),
12                    origin.p + Vector3.new(0,i,0))
13 
14        cam.CoordinateFrame = cf
15 
16        lastTick = tick()
17    end
18end
Ad

Answer this question