Page 1 of 2

This may be very noob, but Particle Collision?

Posted: Wed Oct 21, 2009 7:22 pm
by DustinEwan
Maybe I'm just not very observant or maybe I don't know how to use the search function properly, but how do you implement collision testing for particles?

Creating bodies and shapes, that's all fine, but I can't seem to figure out how to do the same for particles.

(Sorry if this has been covered before)

Re: This may be very noob, but Particle Collision?

Posted: Wed Oct 21, 2009 8:10 pm
by TechnoCat
Is this checking particles against other particles? Or checking particles against shapes and areas?

Re: This may be very noob, but Particle Collision?

Posted: Wed Oct 21, 2009 8:28 pm
by DustinEwan
The latter.

Edit: For further explanation, the intent is to use this for a Bullet Hell style shmup. So I need to check one group of particles against enemy entities, the other group of particles against the player. Should be the same code basically, but yeah.

Re: This may be very noob, but Particle Collision?

Posted: Thu Oct 22, 2009 11:17 am
by Almost
I would probably just manually create and track "objects" across the screen, and for each "shot", test if it is touching the player.
for example:

--make circles
circle = {}
circle.insert({x=100,y=100,vx=50,vy=50,size=5})
circle.insert({x=500,y=200,vx=-30,vy=80,size=8})

--update circles
for i,circle in ipairs(circles) do
circle.x = circle.x + vx*dt
circle.y = circle.y + vy*dt
if math.sqrt((player.x-circle.x)*(player.x-circle.x) + (player.y-circle.y)*(player.y-circle.y) ) < size then
--hurt player.
end
end

--draw circles
for i,circle in ipairs(circles) do
love.graphics.circle(love.draw_fill,circle.x,circle.y,circle.size)
end

Re: This may be very noob, but Particle Collision?

Posted: Thu Oct 22, 2009 3:57 pm
by DustinEwan
Ah, yes, that's one solution, but I was hoping to use Love.Physics for collision testing, since they were kind enough to include that for us :)

I appreciate your suggestion and I may fall back on something like this, but the ParticleSystem is so damn sweet I gotta use it if I can!

Re: This may be very noob, but Particle Collision?

Posted: Mon Oct 26, 2009 8:43 am
by Rabbitbunny
I find that a quadtree works quite well.

http://github.com/samuel/lua-quadtree

Re: This may be very noob, but Particle Collision?

Posted: Mon Oct 26, 2009 6:43 pm
by DustinEwan
Ah, yeah, that's a good substitute for the standard box collision technique, but is there not a way to test for collision on individual particles?

I know that creating and tracking custom objects is the simplest solution for detecting collision, but you lose the motion functionality of the particle system.

Re: This may be very noob, but Particle Collision?

Posted: Tue Oct 27, 2009 4:20 am
by Geti
it isnt the particlesystem (a subset of love.graphics) you want to worry about, it is love.physics, the box2d implementation.
you'll want to set the callback of the world the particles and whatever they're colliding in exist in, with World:setCallback( somefunction ) where somefunction is a lua function defined with the arguments a, b and c (or object1, object2, contact for more readability). that function should handle what happens when a (object1) collides with b (object2) with the stuff contained by c (contact), which is all of the collision data (like friction and the like). look in the destruction demo for a really lazy implementation of this method of collision detection.

Re: This may be very noob, but Particle Collision?

Posted: Wed Oct 28, 2009 7:14 pm
by DustinEwan
Actually, the destruction demo was where I first saw it happen :)

However, I don't really understand how the necessary bodies/shapes can be dynamically generated for each of the particles.. maybe I'm missing something?

Re: This may be very noob, but Particle Collision?

Posted: Wed Oct 28, 2009 7:52 pm
by Robin
DustinEwan wrote:However, I don't really understand how the necessary bodies/shapes can be dynamically generated for each of the particles.. maybe I'm missing something?
I'm not sure what you mean here... doesn't reading the source give you the necessary information?