--code snippet
local recoilcf = cfnew()
local camrecoilcf = cfnew()
local to_recoilcf = cfnew()
local to_camrecoilcf = cfnew()
run.RenderStepped:Connect(function(dt)
local framerate = 1/dt
local ns = (framerate/60)
local speed = math.min(1, 1/ns)
recoilcf = recoilcf:Lerp(to_recoilcf, .4 * speed)
camrecoilcf = camrecoilcf:Lerp(to_camrecoilcf, .4 * speed)
camera.CFrame *= camrecoilcf
view_model.Root.CFrame *= recoilcf
to_recoilcf = to_recoilcf:Lerp(CFrame.new(), .1 * speed)
to_camrecoilcf = to_camrecoilcf:Lerp(CFrame.new(), .2 * speed)
end)
user.InputBegan:Connect(function(ss)
if ss.UserInputType == Enum.UserInputType.MouseButton1 then
to_recoilcf = to_recoilcf* CFrame.new(0,0, pushback) * CFrame.Angles(pitch, yaw, roll)
to_camrecoilcf = to_camrecoilcf*CFrame.new(0,0, pushback/3) * CFrame.Angles(pitch/4.5, yaw/3, roll/3)
end
end)
for some reason whenever i manipulate the camera’s CFrame, (this script provided is just an example - it happens across all my systems which utilize camera.CFrame)
even when factoring in deltaTime as you can see, and believe me it works for everything EXCEPT the camera. I’m a little bit lost here. A year ago I would do the same thing with no issues.
Has roblox changed anything related to the camera? It’s really annoying I can’t do any camera manipulation, it doesnt scale to deltaTime, and its always higher on high FPS
It’s most likely because you’re clamping the speed, effectively removing the purpose of deltaTime. If you want the speed to be higher or lower, just multiply or divide it.
Fixed code:
--code snippet
local recoilcf = cfnew()
local camrecoilcf = cfnew()
local to_recoilcf = cfnew()
local to_camrecoilcf = cfnew()
run.RenderStepped:Connect(function(dt)
local framerate = 1/dt
local ns = (framerate/60)
local speed = 1/ns / 10
recoilcf = recoilcf:Lerp(to_recoilcf, .4 * speed)
camrecoilcf = camrecoilcf:Lerp(to_camrecoilcf, .4 * speed)
camera.CFrame *= camrecoilcf
view_model.Root.CFrame *= recoilcf
to_recoilcf = to_recoilcf:Lerp(CFrame.new(), .1 * speed)
to_camrecoilcf = to_camrecoilcf:Lerp(CFrame.new(), .2 * speed)
end)
user.InputBegan:Connect(function(ss)
if ss.UserInputType == Enum.UserInputType.MouseButton1 then
to_recoilcf = to_recoilcf* CFrame.new(0,0, pushback) * CFrame.Angles(pitch, yaw, roll)
to_camrecoilcf = to_camrecoilcf*CFrame.new(0,0, pushback/3) * CFrame.Angles(pitch/4.5, yaw/3, roll/3)
end
end)
I also see that you’re trying to use some optimizations like saving global variables into local variables, but those have been useless since half a decade ago. Roblox has done the optimizations for global variables since then, so you’re wasting more speed by creating a local variable for those.
Thanks for the reply, my code for deltaTime adjustments works fine, except for the camera. Your code snippet makes my camera and all other systems which rely on the speed variable go crazy. Like jittery as hell.
As for the global variables, do you have any evidence for that? I’m aware they’re micro-optimizations, but still.
Yeah, which is why I said you can modify it by changing the divisor amount. I’m not actively using your game system so I have no clue how much these values affect it.
There used to be a post from a Roblox admin but I can’t find it anymore.
Here’s some benchmarks though.
Code:
local sum = 0
for i = 1, 10 do
local startingTime = os.clock()
for i = 1, 1000000 do
local v = CFrame.new(0, 0, 0)
end
sum += os.clock() - startingTime
end
sum /= 10
print("no optimizations: ".. sum)
local cframeNew = CFrame.new
local sum = 0
for i = 1, 10 do
local startingTime = os.clock()
for i = 1, 1000000 do
local v = cframeNew(0, 0, 0)
end
sum += os.clock() - startingTime
end
sum /= 10
print("micro-optimizations: ".. sum)
Results:
no optimizations: 0.08961044999959995
micro-optimizations: 0.09193983000004664
The difference is so tiny it doesn’t make sense to choose to write more lines of code.
Edit: I misread your code and I assumed you were using the constructor as the optimization, instead of storing the CFrame. Apologies.
what exactly does your code do thats different? since what im trying to say is that the deltatime adjustments were already correct and work for EVERYTHING except the camera.CFrame. its more about why does the camera not work with it. the speed variable is simply a multiplier in my case, where if you have 60 fps its 1, 120fps its 0.5, etc, so the lerp alpha is adjusted
It’s hard to catch with the eye, but it seems the speed or interpolation alpha is the same, regardless of FPS, even when applying it to the camera.
That means my speed variable, aka deltaTime multiplier, works perfectly fine. It’s just for whatever reason, the actual CFrame ‘adjustment’ (how far the camera will move) is higher. This sounds very impossible and unexplainable, because :Lerp() should NOT result in bigger CFrames on high FPS. It would only result in a faster interpolation if the FPS was higher and not accounted for.
Camera magically increases CFrame even via lerp function (which shouldnt happen???) and it’s ONLY the camera??? This issue boggles my mind.
Edit: Even after printing the camera recoil CFrames… they’re all the same high, low FPS, whatever FPS. Yet for some reason it results in larger camera movement on high FPS.
Sounds like #bug-reports:engine-bugs to me.
Bump still havent found a solution this is turning into a serious setback. Literally every cframe code for the camera doesnt work with higher fps regardless of deltaTime accounted for.
Bump, it seems my camera is simply sensitive to CFrame changes (which it shouldnt be), if anybody can report this in engine bugs i can provide a repo in PM, as i dont have access