Flare physics being affected by differences in FPS?

Hello, I am still relatively new to the world of programming, I at the moment pick apart code till it works the way I want it to. So, bear with me. (I honestly cannot tell if they are being affected or not, but my results point to they are)

  1. What do you want to achieve?
    Fix the flares from being affected by high FPS.
    (see “@ 60 FPS vs @ 240 FPS” [NO 60FPS TICK] for reference)

  2. What is the issue?
    Movement, possibly despawn (lifetime) and FXCounter are being affected by FPS.

  3. What solutions have you tried so far
    Added *60 -60 +60 to the “lastTick” variable and changed everything to delta time, yet I see no change.

  4. My findings:
    Initial velocities: 259.633544921875 / 259.7339782714844 / 259.54248046875
    @ 60 FPS | no 60fps tick.
    Initial velocities: 258.828125 / 259.55560302734375 / 258.6429138183594
    @ 60 FPS yes 60fps tick.

    Initial velocities: 262.847412109375 / 262.4277038574219 / 262.4923095703125
    @ 240 FPS no 60fps tick.
    Initial velocities: 262.29150390625 / 262.7029724121094 / 262.7797546386719
    @ 240 FPS yes 60fps tick.

  5. The code:

local gravity = Vector3.new(0, -workspace.Gravity / 10, 0)

local lastTick = tick()

rs.RenderStepped:Connect(function()
	local t = tick() - lastTick
	lastTick = tick()

	local timedGravity = gravity * t
	
	for _,v in pairs(cs:GetTagged("FlareAttachment")) do
		local movement = v.Velocity.Value.Magnitude * t * 1.05
		v.FXCounter.Value = v.Lifetime.Value * math.random()
		
		if v.Lifetime.Value > 0 then
			v.Lifetime.Value = v.Lifetime.Value - t
			
			v.Smoke.Enabled = true
			v.Fire:Emit(v.FXCounter.Value)
		else			
			v.Smoke.Enabled = false
			return cs:RemoveTag(v, "FlareAttachment"), game.Debris:AddItem(v, 30)
		end

		v.WorldCFrame = v.WorldCFrame + (v.Velocity.Value * t)
		v.AttachmentL.Value.WorldCFrame = v.WorldCFrame + Vector3.new(0,0,-.5)
		v.AttachmentR.Value.WorldCFrame = v.WorldCFrame + Vector3.new(0,0,.5)
		
		local dragFactor = 1.05
		local drag = dragFactor * t + 1
		v.Velocity.Value = (v.Velocity.Value + timedGravity) / drag
		
		print(v.Velocity.Value.Magnitude)
	end
end)
2 Likes

Use heartbeat, it runs every physical simulation, it might help

1 Like

This is not the true delta time. RenderStepped already provides a delta time parameter, so what you’re doing here is not only redundant but it’s inaccurate as well and is likely at least part of your problem.

1 Like

No difference, still going around ~260-263. BTW this isn’t something like a part that is affected by the physics simulation by being unanchored etc.

1 Like

I’ve tried changing everything to deltatime, I see no difference. They provide the same velocities.

That’s a weird formula with division for drag, that will lead to exponential decay which needs a different formula like this lerp one.

I think it should be

velocity = acceleration * dt

So it should be

v.Velocity.Value += gravity * dt

local dragFactor = 0.05
v.Velocity.Value -=  dragFactor *v.Velocity.Value* dt

Where drag = -v*coefficient, you could also make it squared drag = -(v^2)*coefficient

2 Likes

still does the opposite of what i want it to do, at 240fps it reaches ~262, while 60fps will only reach ~258

but also thank you for bringing this to my attention

1 Like