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

How would I go about rotating a the camera?

Asked by 4 years ago
wait(1)


workspace.CurrentCamera.CFrame = CFrame.new(0,0,0) * CFrame.Angles(math.rad(25), 1, 1)

I tried this but it didn't work. What I am trying to create is rotating the camera, like in gta 5 when you're in an airplane and you turn. Does anyone know what I should use to achieve it?

0
I don't have the answer but make sure you do math.rad(1) as well. User#25069 0 — 4y
0
It doesn't matter if they're wrapped in math.rad or not. goodadmins 111 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

I've been messing around with this for the past half-hour or so, and the only way I can seem to rotate the camera is to use the wait() method of RenderStepped.

I even tried binding the function to a renderstep, which's priority is OVER that of Roblox's default camera script, but to no avail. This is an extremely weird functionality, and (from what I've found) has no documentation on it.

What I've done in the script below is using a while loop, with function, as to not hault the main thread, and rotate the camera 1 degree every 1/30th of a second (in theory):

rs = game:GetService("RunService")
cam = game.Workspace.CurrentCamera
rot = 0
spawn(function() 
    while rs.RenderStepped:Wait() do
        cam.CFrame = cam.CFrame* CFrame.Angles(0, 0, math.rad(rot))
    end
end)
for i=1,360 do
    wait()
    rot=rot+1
end

But, what is REALLY confusing, is that, as I said, the function fails to work at all with any delay under that of the current frame time (supposedly 1/60th of a second), though even though :BindToRenderStep() is the frame-time, it still doesn't work, as shown below:

rs = game:GetService("RunService")
cam = game.Workspace.CurrentCamera
rs:BindToRenderStep("1", Enum.RenderPriority.Camera.Value+1, function() 
    cam.CoordinateFrame = cam.CoordinateFrame* CFrame.Angles(0, 0, math.rad(90))
end)

If anyone can find out why this is the case, I'd be interesting in knowing!

EDIT: Both scripts work now. Don't use the first one, as creating a new thread is bad. I stupidly set the RenderPriority to Enum.RenderPriority.Camera.Value-1 rather than Enum.RenderPriority.Camera.Value+1. My bad, lol

0
That is indeed very weird, maybe it is a glitch within the current LUA version. goodadmins 111 — 4y
0
I'm pretty sure it is. Never seen this behavior before Internal_1 344 — 4y
0
Moderator "Potato" in the Discord notified me that roblox's camera runs at priority 200, and I just realized that I had the priority set to 199, rather than 201. Both should work flawlessly now. Still weird that setting the cameraType to scriptable didn't force it to work. Internal_1 344 — 4y
Ad

Answer this question