Hello, em... so I've tried to make particles for the first time, basically, and while I thought that I got it, something strange happens.
I've made a rain effect which, upon start, starts to go off every 5 seconds and go on again.
Here's a video:
[video=youtube;PZNWleZ5Pr8]https://www.youtube.com/watch?v=PZNWleZ5Pr8[/video]
Here's the code:
[B]The code that starts the rain:[/B]
[CODE]
if CLIENT then
local rainingEffect = false
local rainSound
local function Think()
if ( !rainingEffect ) then
local rain = EffectData();
util.Effect( "rain", rain );
rainingEffect = true;
else
if ( !rainSound ) then
rainSound = CreateSound(LocalPlayer(), "weather/rain_loop.wav")
else
if ( !rainSound:IsPlaying() ) then
rainSound:Play()
end
if SURVIVAL:IsOutside(LocalPlayer():EyePos()) then
rainSound:ChangeVolume(0.6)
elseif !SURVIVAL:IsOutside(LocalPlayer():EyePos()) then
if util.IsSkyboxVisibleFromPoint( LocalPlayer():GetPos() ) then
rainSound:ChangeVolume(0.3)
else
rainSound:ChangeVolume(0)
end
end
end
end
end
hook.Add("Think", "survivalgm_daynight_rain", Think)
end
[/CODE]
[B]The particle emitter code:[/B]
[CODE]
function EFFECT:Init(data)
self.Data = data
self.Emitter = ParticleEmitter(LocalPlayer():GetPos(), true)
self.Exists = true;
end
function EFFECT:Emit()
self.Data:SetOrigin(LocalPlayer():EyePos() + LocalPlayer():EyeAngles():Forward()*100)
self.Emitter:SetPos(self.Data:GetOrigin())
local n = 16
local m = 512
for i = 1, 100 do
local pos = LocalPlayer():GetPos() + Vector( math.random( -m, m ), math.random( -m, m ), math.min( 100, math.random( m, 2 * m ) ) )
local particle = self.Emitter:Add("weather/rain", pos)
particle:SetAngles( Angle( 0, 0, -90 ) );
particle:SetVelocity( Vector( 0, 0, -1000 ) );
particle:SetStartAlpha( 230 );
particle:SetStartSize( 4 );
particle:SetEndSize( 4 );
particle:SetColor( 255, 255, 255 )
particle:SetDieTime(5)
end
end
function EFFECT:Think()
self:Emit()
if !self.Exists then
self.Emitter:Finish()
end
return true;
end
function EFFECT:Render()
end
[/CODE]
I know that I'm probably doing something wrong, but I don't know what. Any help? ^^''
I believe you are spawning too many particles. In your code, EFFECT:Emit() is called each tick in EFFECT:Think(). That's 100 particles per tick. So if we take the usual tickrate of 66, that is 6600 particles per second. Each particle takes 5 seconds to die (SetDieTime(5)), so that means there are 33000 particles all at once. There is, probably, a limit on how many particles there can be at once, and so they stop spawning while the limit is exhausted.
Try reducing the number of particles per tick, even 8 particles per tick is more than you need in most scenarios. You can also reduce die time to 1-2 seconds, and/or make particles disappear on impact (not sure if possible, but probably is, I haven't looked into it).
[QUOTE=typedef state;50766463]I believe you are spawning too many particles. In your code, EFFECT:Emit() is called each tick in EFFECT:Think(). That's 100 particles per tick. So if we take the usual tickrate of 66, that is 6600 particles per second. Each particle takes 5 seconds to die (SetDieTime(5)), so that means there are 33000 particles all at once. There is, probably, a limit on how many particles there can be at once, and so they stop spawning while the limit is exhausted.
Try reducing the number of particles per tick, even 8 particles per tick is more than you need in most scenarios. You can also reduce die time to 1-2 seconds, and/or make particles disappear on impact (not sure if possible, but probably is, I haven't looked into it).[/QUOTE]
So I should add like a timer to regulate the amount of particles at once?
[QUOTE=AlbertoBC;50766479]So I should add like a timer to regulate the amount of particles at once?[/QUOTE]
No, I already told you what you need to do. You need to reduce the amount of particles spawned at once (that loop which spawns them in your effect entity code). Reduce the number of iterations from 100 to something like 16, 8, or even 4, and see what works best. You can also reduce the number of particles by decreasing life time (particle:SetDieTime)
[QUOTE=typedef state;50766522]No, I already told you what you need to do. You need to reduce the amount of particles spawned at once (that loop which spawns them in your effect entity code). Reduce the number of iterations from 100 to something like 16, 8, or even 4, and see what works best. You can also reduce the number of particles by decreasing life time (particle:SetDieTime)[/QUOTE]
Aight. I'll try it. Thanks for the tip!
[editline]24th July 2016[/editline]
[QUOTE=typedef state;50766522]No, I already told you what you need to do. You need to reduce the amount of particles spawned at once (that loop which spawns them in your effect entity code). Reduce the number of iterations from 100 to something like 16, 8, or even 4, and see what works best. You can also reduce the number of particles by decreasing life time (particle:SetDieTime)[/QUOTE]
Holy crap! Instant fix! Thanks so much! (I can't believe I wasted so much time looking for a solution... :v:)
[QUOTE=AlbertoBC;50766538]:snip:[/QUOTE]
I am glad it helped. You should mark the thread as solved.
Sorry, you need to Log In to post a reply to this thread.