How to detect if particles collide with a physics body..??

I bought Particle Candy some days ago and I am really happy that I bought your library !!

What I need is the possibility to detect if some particles collide with a physics body or with a
sprite. I dont know if the way is to take FX Fields…??
Please give me a hint…
Greetings from Berlin Germany [import]uid: 12632 topic_id: 5076 reply_id: 305076[/import]

Hi Michael, Grüsse aus Augsburg :wink:

Sorry for the delayed reply, we’ve been out of office from Jan 13 - 27.

We already planned to include physics driven particles and / or add some useful collision methods with the next release, which should be out soon. [import]uid: 10504 topic_id: 5076 reply_id: 19169[/import]

If there are not too many particles involved, you can also use GetParticle( ), by the way, to loop through the particles and simply compare the current x/y coordinates of a particle with the coordinates of your sprite.

Note the included sample source “Sample_Looping_through_particles”.

This should also do it:

[lua]-- LOOP THROUGH ALL PARTICLES AND COMPARE COORDS
local numParticles = Particles.GetMaxParticles()
local Particle

for i = 1, numParticles do
Particle = Particles.GetParticle(i)
– PARTICLE EXISTS?
if Particle ~= nil then
– WHAT PARTICLE TYPE TO LOOK FOR?
if Particle.PType.name == “MyDeadlyParticles” then
– COMPARE X-COORDS
if Particle.x > MySprite.x - MySprite.width/2 and Particle.x < MySprite.x + MySprite.width/2 then
– COMPARE Y-COORDS
if Particle.y > MySprite.y - MySprite.height/2 and Particle.y < MySprite.y + MySprite.height/2 then
print(“COLLISION!”)
break – PLAYER IS DEAD, ABORT LOOPING
end
end
end
end
end[/lua]
[import]uid: 10504 topic_id: 5076 reply_id: 19200[/import]

About fx fields and next collision methods :

Could add condition on “kill particles once they entered a FX Field” option ? [import]uid: 9328 topic_id: 5076 reply_id: 19579[/import]

What kind of condition would you like to be added?
[import]uid: 10504 topic_id: 5076 reply_id: 19588[/import]

Well , I was thinking about a kind of fieldResistance particle type value.
Assuming this value decreases each time a particle enters a field, the particle would be erased only if this resistance reach 0.

But maybe is there another way to reach that with all the great stuff you already put in your library … [import]uid: 9328 topic_id: 5076 reply_id: 19607[/import]

The main goal is to keep the library’s performance as good as possible, so it’s wise to add features that can be used in a wide range of games only.

But you could loop through your particles and check the distance between a particle and any given x/y coordinate. If the distance between the particle’s coord and this x/y coordinate (which could be the center of an imaginary, particle destroying area) is lower than the areas’s radius, the particle is inside this area. Then you can manipulate the life energy of the particle by your own. Here is a quick sample:
[lua]-- LOOP THROUGH ALL PARTICLES AND CHECK IF A PARTICLE
– IS INSIDE AN IMAGINARY FIELD THAT DAMAGES A PARTICLE.
– PARTICLE GETS DESTROYED ONCE THE DAMAGE REACHES A
– VALUE OF 100.

local Particle, dx, dy

local fieldCenterX = 200
local fieldCenterY = 200
local fieldRadius = 50
local sqrt = math.sqrt
local now = system.getTimer()
local numParticles = Particles.GetMaxParticles()

– LOOP THROUGH PARTICLES
for i = 1, numParticles do
Particle = Particles.GetParticle(i)
– PARTICLE EXISTS?
if Particle ~= nil then
– WHAT PARTICLE TYPE TO LOOK FOR?
if Particle.PType.name == “MyParticlesToDamage” then
– GET DISTANCE BETWEEN PARTICLE AND FIELD’S CENTER
dx = Abs( fieldCenterX - Particle.x )
dy = Abs( fieldCenterY - Particle.y )

– PARTICLE IS INSIDE THIS FIELD’S RADIUS?
if sqrt ( (dx*dx) + (dy*dy) ) < fieldRadius then
Particle.damage = Particle.damage + 0.1
– KILL THIS PARTICLE?
if Particle.damage >= 100 then Particle.killTime = now
end
end
end
end[/lua]

[import]uid: 10504 topic_id: 5076 reply_id: 19686[/import]

OK.
1000 Thx for the code example :slight_smile:

The only downside is that Fields let you handle all this automatically
(that’s the magic of your library).
That’s why I was wishing a new particle type value (or whatever ParticleCandy solution).
But I can understand the choices you have to do for new features.

Anyway, I’ll try to add this in the main loop.
[import]uid: 9328 topic_id: 5076 reply_id: 19687[/import]

Now the new version have exactly what I need, thanks a lot…

Michael [import]uid: 12632 topic_id: 5076 reply_id: 19933[/import]

don´t get it to work, could you please give a short example how to use that with current version, i.e. having physics particles collide with other physics objects and thereby triggering an event? There is not a single example of this in the samples that come with Particle Candy.

My problem is that the name I give the physics particles is nil when I try to use it (I did confirm that there are existing particles). [import]uid: 109677 topic_id: 5076 reply_id: 86392[/import]

I’m often to blogging and i actually admire your content. The article has actually peaks my interest. I am going to bookmark your website and preserve checking for new information.
Gay porn anime hypotonically Big booty shemales pawn Gay teen porn sandal [import]uid: 135934 topic_id: 5076 reply_id: 96174[/import]