Particle System won't emit properly.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Azzla
Prole
Posts: 38
Joined: Sun Mar 29, 2020 2:23 am

Particle System won't emit properly.

Post by Azzla »

Hi. I've been working on my first LOVE2D project for a week or so and I'm trying to add some simple particle effects to the game.

The problem is that every emission call during the game results in particles shooting out on a specific axis, while the particles should just shoot out of the zombie's position in a radial manner. I've tried messing around with these functions listed on the documentation:

Code: Select all

pSystem:setEmissionArea()
pSystem:setDirection()
However both have not solved the issue as setDirection() only allows me to change which axis the particles fly out towards. I want them to fly out radially from my zombie instead. A terrible pseudo-code example to demonstrate the idea: pSystem:setDirection(random_angle_relative_to_center_of_zombie_object). Currently my code for the particle system is as follows:

Code: Select all

particles = {}

function spawnParticle(x, y, speed, pSprite, pFX)
  pFX.x = x
  pFX.y = y
  pFX.pSystem = love.graphics.newParticleSystem(pSprite, 20)
  
  pFX.pSystem:setParticleLifetime(.5,1)
  pFX.pSystem:setLinearAcceleration(-80,-80,80,80)
  pFX.pSystem:setSpeed(speed/2, speed)
  table.insert(particles, pFX)
  
  return pFX
end

function particleUpdate(dt)
  for i,p in ipairs(particles) do
    p.pSystem:update(dt)
  end
end
I am just calling a simple pSystem:emit(numOfParticles) function whenever a bullet collides with a zombie. Any help with this issue will be appreciated, thanks.
libraries: Stalkpile
electronic music stuff: https://soundcloud.com/azzlamusic
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: Particle System won't emit properly.

Post by MrFariator »

By shooting out particles radially, I assume you mean that the particles need to emit in a circle from origin? I have not messed around with löve's particle system much, but as far as I've understood it, to get a radial splash of particles going you need to do something along the lines of:

Code: Select all

-- initialization
local numberOfParticles = 100
local psystem = love.graphics.newParticleSystem(image_goes_here, numberOfParticles)
psystem:setParticleLifetime ( 10,10 )
psystem:setSizeVariation ( 1 )
psystem:setSpeed ( 20, 20 )
psystem:setColors ( 1, 1, 1, 1, 1, 1, 1, 0 )

-- spawn particles
local direction = 0
local increment = (math.pi*2) / numberOfParticles
for i = 1, numberOfParticles do
  psystem:setDirection ( direction )
  psystem:emit (1)
  direction = direction + increment
end
So essentially instead of using setLinearAcceleration(), you manually go through the angles to which you want particles to spawn, and emit the particles one by one.

Example of output (but 30 particles instead of 100, and speed 10 instead of 20; not a perfectly looped gif hence the stutter):
Image
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Particle System won't emit properly.

Post by pgimeno »

I believe you're supposed to use ParticleSystem:setLinearAcceleration for that, see example in love.graphics.newParticleSystem.
User avatar
Azzla
Prole
Posts: 38
Joined: Sun Mar 29, 2020 2:23 am

Re: Particle System won't emit properly.

Post by Azzla »

MrFariator wrote: Sun Mar 29, 2020 1:15 pm

Code: Select all

-- spawn particles
local direction = 0
local increment = (math.pi*2) / numberOfParticles
for i = 1, numberOfParticles do
  psystem:setDirection ( direction )
  psystem:emit (1)
  direction = direction + increment
end
So essentially instead of using setLinearAcceleration(), you manually go through the angles to which you want particles to spawn, and emit the particles one by one.
Exactly the effect I was looking for. Thanks! :D
libraries: Stalkpile
electronic music stuff: https://soundcloud.com/azzlamusic
Post Reply

Who is online

Users browsing this forum: No registered users and 45 guests