Hi guys!
I’m currently working on particle emitter for generating grass field. I’m in the process of optimizing the emitter so the game doesn’t lag… except I am not sure where to start. I thought about preloading images and locally running particle emitter(not really sure running locally would help though…). Is there anything else that I should watch out for? (Especially when the player walks in a densely packed particle grass)?
you could only run the emitter if the local player is a certain distance from the area.
1 Like
Exactly what @RomeoEDD said, but instead of the Players position, use the Camera’s position
This should be in a local script
local Cam = workspace.CurrentCamera
local GrassParticles = --Put the parent of all the parts with particle effects here
while wait(0.1) do
for i,v in pairs(GrassParticles:GetChildren()) do
if (Cam.CFrame.p - v.Position).Magnitude > 10 then --Mess with the number 10, until you find a number that works nicely
v.GrassParticle.Enabled = false
else
v.GrassParticle.Enabled = true
end
end
end
Please note I have not tested this out so I have no idea if this works how its supposed to.
2 Likes
Please don’t use wait as a condition for a while loop. It’s not good practice for loops. Another note that CFrame.p is deprecated and it’s PascalCase variant, CFrame.Position, is preferred for updated works. It’s also more clear what property you’re trying to access.
5 Likes