How could I use delta time to have velocity consistency?

I’m making my own particle emitter, and I’m having a little trouble making it’s velocity consistent throughout different fps.

RunService.PostSimulation:Connect(function(deltaTime)
	if self.rate > 0 then
		if latest == nil or os.clock() - latest >= 1 / self.rate then
			self:createParticle()

			latest = os.clock()
		end
	end

	for index, particle in ipairs(self.particles) do
		if particle.velocity == nil then
			particle.velocity = particle.direction * (particle.speed * deltaTime)
		end
		
		if os.clock() - particle.birthday >= particle.lifetime then
			particle.body:Destroy()
			table.remove(self.particles, index)
			return
		end
		
		particle.velocity += self.acceleration * deltaTime^2
		
		particle.body.WorldPosition += particle.velocity
	end
end)


I hope the video can give you a clear indication of what I don’t what happening.

Thank you!

This is semi-implicit euler integration. Try removing the squared term as it is incorrect (according to the link).

Otherwise you might have to use another type of integration.

Ah, thank you! I actually was confused a bit on this because in school I got taught something along the lines of what I wrote in my code. This blog was very informational; I learned a lot! I’ll change my code relative to this new information :smile:

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