Sliding using RunService going further the lower the fps

Ok so, i made this sliding script but (this part) that is the part that makes the player slow down after some time changes depending on their fps

				PlrSlide = RunSer.RenderStepped:Connect(function(deltatime)
					RepeatedTimes += 1
					LinearVelocity.MaxForce = 40000
					LinearVelocity.Attachment0 = HRP.RootAttachment
					LinearVelocity.VectorVelocity = HRP.CFrame.LookVector * (100 - RepeatedTimes)
					if RepeatedTimes >= 100 then
						StopSlide()
					end
				end)

If the player is playing at 240fps he slides for 0.4s
and if the player is playing at 60fps he slides for 1.2s
how can i fix it for both to be 0.4?

Just a quick solution, you can probably use deltatime to track how long they will slide, and check it like this:

local Slidetime = 0.4
local CurrentTick = 0

			PlrSlide = RunSer.RenderStepped:Connect(function(deltatime)
					CurrentTick += deltatime
					LinearVelocity.MaxForce = 40000
					LinearVelocity.Attachment0 = HRP.RootAttachment
					LinearVelocity.VectorVelocity = HRP.CFrame.LookVector * (100 * (1 - (CurrentTick / Slidetime))) --prob right or wrong when slowing the velocity down, sorry if it is wrong, just typed it quickly :(
					if RepeatedTimes >= Slidetime then
						CurrentTick = 0
						StopSlide()
					end
				end)

So, when every frame is rendered, the time difference between the frames would be added, making it decently consistent. Lower the FPS, the higher the deltatime, higher the FPS, the lower the deltatime. Hope this works :slight_smile:

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.