Hello,
I’m relatively new to coding; I’m currently getting more experience with camera manipulation.
Firstly, if I understand RenderStep correctly it’s used to call a function at a certain period of studio’s startup/current state (e.g. in this case when the default roblox camera scripts are loaded)?
Secondly, I’ve noticed the code below runs in a continuous loop. If I were to remove the Bind and manually create a while loop why does it not work?
function cameraChange()
local camera = workspace:WaitForChild("Camera")
camera.CFrame = CFrame.lookAt((dummy.HumanoidRootPart.Position + Vector3.new(0,3,-8)),dummy.HumanoidRootPart.Position) * CFrame.Angles(-0.05,0,0)
end
runService:BindToRenderStep("IsometricCamera",Enum.RenderPriority.Camera.Value,cameraChange)
While loop instead of using RenderStep that doesn’t work
function cameraChange()
local camera = workspace:WaitForChild("Camera")
camera.CFrame = CFrame.lookAt((dummy.HumanoidRootPart.Position + Vector3.new(0,3,-8)),dummy.HumanoidRootPart.Position) * CFrame.Angles(-0.05,0,0)
end
while task.wait() do
cameraChange()
end
function cameraChange()
local camera = workspace:WaitForChild("Camera")
camera.CFrame = CFrame.lookAt((dummy.HumanoidRootPart.Position + Vector3.new(0,3,-8)),dummy.HumanoidRootPart.Position) * CFrame.Angles(-0.05,0,0)
end
while task.wait() do
cameraChange()
end
BindToRenderStepped Is used to Bind a function at a Priority, It allows you to run things before others, and things after others, Its basically RenderStepped, but under a set order, as RenderStepped will fire in any order.
The Reason it runs in a loop, is because RenderStepped runs prior to something Rendering every frame, which if you have 40 FPS, every 1/40 of a second, this event will fire 40 times a second.
Its best that you use workspace.CurrentCamera, whixh is much faster than waiting for the Camera Instance.
Doing this would be the exact same as doing RunService.Heartbeat which is slower, as it is Prioritized last.
Roblox Recommends you Handle Camera Stuff with RenderStepped however.
So in this case, this loop doesn’t work because as you said it’s prioritized last? And even if this is the case shouldn’t it still override the default camera either way since it’s changing the CFrame constantly?
The while loop is changing the CFrame yes, but the Core scripts are changing the camera CFrame too if you dont turn the camera type to: camera.CameraType = Enum.CameraType.Scriptable
Otherwise core scripts still manipulating the camera. But, do not use a while loop to manipulate the camera, use the RenderStep as suggested