This may be very noob, but Particle Collision?

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.
DustinEwan
Prole
Posts: 18
Joined: Wed Oct 21, 2009 7:20 pm

This may be very noob, but Particle Collision?

Post 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)
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

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

Post by TechnoCat »

Is this checking particles against other particles? Or checking particles against shapes and areas?
DustinEwan
Prole
Posts: 18
Joined: Wed Oct 21, 2009 7:20 pm

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

Post 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.
User avatar
Almost
Prole
Posts: 42
Joined: Fri Aug 21, 2009 8:04 pm
Location: Canada
Contact:

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

Post 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
DustinEwan
Prole
Posts: 18
Joined: Wed Oct 21, 2009 7:20 pm

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

Post 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!
Rabbitbunny
Prole
Posts: 3
Joined: Thu Oct 15, 2009 9:33 am

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

Post by Rabbitbunny »

I find that a quadtree works quite well.

http://github.com/samuel/lua-quadtree
DustinEwan
Prole
Posts: 18
Joined: Wed Oct 21, 2009 7:20 pm

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

Post 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.
Geti
Party member
Posts: 112
Joined: Tue Oct 20, 2009 6:38 am

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

Post 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.
DustinEwan
Prole
Posts: 18
Joined: Wed Oct 21, 2009 7:20 pm

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

Post 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?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post 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?
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests