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

Converting CFrame to Renderstep?

Asked by 4 years ago

How would I convert this:

while true do
    script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0,-0.05,0)
    wait(0.02)
end

To renderstep so my moving parts would render in the player's client instead of the game itself? Sorry, I've never used renderstep before.

1 answer

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
4 years ago
Edited 4 years ago
local RunService = game:GetService("RunService")

function onRenderStep(dt)
    script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0, -2.5*dt, 0)
end

RunService:BindToRenderStep("BindingName", Enum.RenderPriority.Camera.Value - 1, onRenderStep)

This binds the function, onRenderStep, to run every render frame before the camera controls. The function called receives an argument which represents how much time has passed since the last frame. This value is then multiplied with your angular velocity (-0.05/0.02) to calculate the number of radians to rotate by. There are also other events that can be listened to that occur at various points in the frame which you can see in the docs for RunService.

Ad

Answer this question