How to use deltaTime without using .RenderStepped?

This is once again, and extension off of a different recoil post.

Anyways, I have a spring module that I’m trying to use to simulate recoil, and it requires that I use deltaTime for something I don’t understand. Now that’s cool and all, but the only way I know how to use deltaTime, is by doing Runservice.RenderStepped.

Here’s my code:

local Springs = require(game.ReplicatedStorage.springs)
local Camera = workspace.CurrentCamera

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local runServ = game:GetService("RunService")

Springs.Recoil = Springs.create()

function Shove(deltaTime)
	Springs.Recoil:shove(Vector3.new(0.03,0,0))
	spawn(function()
		wait(.15)
		Springs.Recoil:shove(Vector3.new(-0.03,0,0))
	end)
	
	local recoil = Springs.Recoil:update(deltaTime)
	
	workspace.Part.CFrame = workspace.Part.CFrame * CFrame.Angles(recoil.x,recoil.y,recoil.z)
end


mouse.Button1Down:Connect(function()
	runServ.RenderStepped:Connect(function(deltaTime)
		Shove(deltaTime)
		wait(10)
	end)
end)

YouTube Demonstration: https://www.youtube.com/watch?v=e5apifNE1as

As you can see, due to me using RenderStepped, it causes it to run every second or something. I don’t want that because I’m attaching THAT to the camera. It just looks very jittery and stupid.

Any help would be appreciated :smiley:

1 Like

I would recommend using os.time() to calculate the amount of time that passed. os | Documentation - Roblox Creator Hub
For example,

 local waittime = os.time()  -- gets an old os.time() value and its saved into the variable
-- the event prints how much time has passed since the part was touched
part.Touched:connect(function()
local timepassed = os.time() - waittime -- checks the amount of time in seconds by findingdifference between a current and old os.time() value
print(timepassed) -- prints the amount of time since the part was last touched
waittime = os.time() -- sets waittime to a new os.time() value to keep up to date
end)
1 Like

I’ll look into this! Thanks!

(30 charactersssssss)

You’re welcome. P.S. if you want it to be more exact to milliseconds instead of an integer, you’ll want to use tick(). You can only use tick from a client standpoint but it can be used here too.

Rather than using os.time() or tick(), there is now os.clock() which is like tick(), but doesn’t use the local time zone, it uses a standard time. I’d recommend using this versus os.time() because it is more accurate, and use it over tick() because it does the same thing but better.