I made an almost perfect collision detection system:
However... the problem is of course the FPS. There were only 32 entities in there, and what I'm doing is looping through each entity every update() and then looping through every entity again to check if two entity's bounding boxes are colliding. This is obviously a really bad thing to do in Lua because it's an interpreted language.
Help?
Please don't say wait for the new Love collision stuff because that isn't helping, that's a delay.
I only started using Love yesterday and already have a base game system working. It's just the collision...
Collision Detection
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Collision Detection
Last edited by Kuromeku on Sun Jul 20, 2008 6:55 pm, edited 1 time in total.
Re: Collision Detection
You could try just looping through objects which are close to the object.
- Dr. Magnusson
- Prole
- Posts: 22
- Joined: Sun Jul 20, 2008 6:10 pm
Re: Collision Detection
Why did you post the same picture 3 times?
And how do you expect us to help you when you haven't posted any of the actual code for detecting collisions?
Also, does the energy of the boxes transfer to others on collision?
And how do you expect us to help you when you haven't posted any of the actual code for detecting collisions?
Also, does the energy of the boxes transfer to others on collision?
Re: Collision Detection
It doesn't transfer yet. I planned to do that later.
This is the code that checks if two bounding boxes collide.
That's the code that actually causes the bad FPS.
And as for checking only entities that are close, I still have to loop through every entity for that.
This is the code that checks if two bounding boxes collide.
Code: Select all
local ba = self:getBoundingBox();
local bb = entity:getBoundingBox();
-- Sort out the bounding boxes into groups.
ba = { {ba[1], ba[2]}, {ba[2], ba[3]}, {ba[3], ba[4]}, {ba[4], ba[1]} };
bb = { {bb[1], bb[2]}, {bb[2], bb[3]}, {bb[3], bb[4]}, {bb[4], bb[1]} };
-- Loop through each bounding box structure.
for k, v in pairs(ba) do
for k2, v2 in pairs(bb) do
local collision, x, y = hate.util.linesCollide(v[1], v[2], v2[1], v2[2]);
-- Check if there is a collision.
if (collision) then return true, x, y; end;
end;
end;
-- Return false because there was no collision.
return false;
And as for checking only entities that are close, I still have to loop through every entity for that.
Re: Collision Detection
Wow, that's a really crappy FPS. Do you check every object against every other?
Re: Collision Detection
That's what I was wondering..rude wrote:Wow, that's a really crappy FPS. Do you check every object against every other?
Re: Collision Detection
Yeah rude, I do:
Also rude, did you make Love? If so then good job, it's awesome.
I was thinking I could do the collision checking in a thread:
But it still does it (I really don't think that's running a seperate thread like it should do).
Code: Select all
for k, v in pairs(hate.entities.spawned) do
for k2, v2 in pairs(hate.entities.spawned) do
-- I check if the entities are close to each other here.
end;
end;
I was thinking I could do the collision checking in a thread:
Code: Select all
coroutine.resume(coroutine.create(function()
for k, v in pairs( hate.entities.getAll() ) do
v:onUpdate(delta);
v:onHandlePhysics();
end;
hate.error = love.timer.getFPS().." FPS!";
end));
Re: Collision Detection
And with only 32 objects? I suppose there's no chance you'll post the full super-secret source? (So I can benchmark it myself).
You could implement some kind of spatial partitioning (grid, quadtree). That would keep you from having to check every object with every other, and it should speed up things considerably.
But still, an FPS like that with only 32 objects suggests that the collision detection algorithm itself is to blame. And it does look kind of slow. For instance, you create two tables for each iteration ... that can't be good.
You could implement some kind of spatial partitioning (grid, quadtree). That would keep you from having to check every object with every other, and it should speed up things considerably.
But still, an FPS like that with only 32 objects suggests that the collision detection algorithm itself is to blame. And it does look kind of slow. For instance, you create two tables for each iteration ... that can't be good.
Kudomiku wrote:Also rude, did you make Love? If so then good job, it's awesome.
- What kind of shapes do you need?
- What kind of collision response do you need?
- Is there a lot of static geometry in your game? (I.e. terrain.)
- Tell us more!
<obvious-pun>Yes, I make LÖVE with mike.</obvious-pun>Kudomiku wrote:Also rude, did you make Love? If so then good job, it's awesome.
Re: Collision Detection
Hello this is the source.
http://kudomiku.com/storage/hate.rar
I don't know how to make it a .love yet, like I said, I haven't been using Love for long.
And as for the other collision methods you talked about, I don't really know because I've never done collision before. This is my first time.
When the game loads, you'll see some falling prop_physics, you can grab them by clicking on them.
P.S: I managed to speed it up by checking if the entity is POSSIBLE to collide with it (checking if it's within possible distance). That manages 32 entities fine, but my goal now is 128 entities (which it currently can't handle), could you help? Anyway, take a look at my source and see how things are.
I plan to make it like a 'gamemode' sandbox. So I can make little fun Lua gamemodes like top-down shooters, side-scrollers, or whatever with ease.
Thanks for your help.
http://kudomiku.com/storage/hate.rar
I don't know how to make it a .love yet, like I said, I haven't been using Love for long.
And as for the other collision methods you talked about, I don't really know because I've never done collision before. This is my first time.
When the game loads, you'll see some falling prop_physics, you can grab them by clicking on them.
P.S: I managed to speed it up by checking if the entity is POSSIBLE to collide with it (checking if it's within possible distance). That manages 32 entities fine, but my goal now is 128 entities (which it currently can't handle), could you help? Anyway, take a look at my source and see how things are.
I plan to make it like a 'gamemode' sandbox. So I can make little fun Lua gamemodes like top-down shooters, side-scrollers, or whatever with ease.
Thanks for your help.
Re: Collision Detection
It's just a renamed .zip file.Kudomiku wrote:I don't know how to make it a .love yet, like I said, I haven't been using Love for long.
If you can make do with circles, that should be fast enough for you. Check out the attatched demo. With 128 objects, it's stable around 110 FPS on my laptop.
I would help you out more, but this is what I have time for right now.
- Attachments
-
- collision.love
- (1.31 KiB) Downloaded 382 times
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 5 guests