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)
This may be very noob, but Particle Collision?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 18
- Joined: Wed Oct 21, 2009 7:20 pm
- 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?
Is this checking particles against other particles? Or checking particles against shapes and areas?
-
- Prole
- Posts: 18
- Joined: Wed Oct 21, 2009 7:20 pm
Re: This may be very noob, but Particle Collision?
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.
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?
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
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
-
- Prole
- Posts: 18
- Joined: Wed Oct 21, 2009 7:20 pm
Re: This may be very noob, but Particle Collision?
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!
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!
-
- Prole
- Posts: 3
- Joined: Thu Oct 15, 2009 9:33 am
-
- Prole
- Posts: 18
- Joined: Wed Oct 21, 2009 7:20 pm
Re: This may be very noob, but Particle Collision?
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.
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?
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.
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.
-
- Prole
- Posts: 18
- Joined: Wed Oct 21, 2009 7:20 pm
Re: This may be very noob, but Particle Collision?
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?
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?
- 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?
I'm not sure what you mean here... doesn't reading the source give you the necessary information?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?
Help us help you: attach a .love.
Who is online
Users browsing this forum: Bing [Bot], Google Adsense [Bot] and 3 guests