Collisions

BlitzMax Forums/BlitzMax Beginners Area/Collisions

Eric(Posted 2006) [#1]
How is everyone correctly handling Collisions.

I might be thinking wrong here.. But the steps I am taking are the following.. When I am drawing an Object I also write it to a collision Layer.

When I am updating an Object I am checking it against Each collision layer. Then Process the Array of Objects returned. Then I reset the Collisions and start over.

Is this the correct and most efficient way to handle this?

It seems to be bogging down when I get 30 or more objects. Is this normal? Or is the slowdown most likely somewhere else in my code.

I have been toying around with checking the distance to an object but then the collisions don't look accurate.

What is everyone else doing?

Regards,
Eric


kronholm(Posted 2006) [#2]
Move the objects at only one pixel per loop. If it needs to move faster, run the one-per-pixel loop more than once. For crude collision I just use basic rectangle if statements (if ball.x > brick.x+brick.width/2) etc. Then it's on to imagescollide. Works really well and runs very fast with a lot of objects at the same time (5000+, running at 8x pixel-loop speed), plus you always get correct collisions, nothing with overlapping or that kind of crap.

I have no idea if this is the "correct" way to do it, or what it's called, but it works VERY well for me.


Dreamora(Posted 2006) [#3]
No thats not the correct way:

1. Write all your static objects to a collision layer where only static objects reside in.

2. write all dynamic objects to the dynamic layer that shall send collisions, without reading their collision.

3. process all objects that shall receive collisions (not that are normally only a very very few) by writting it to the dynamic layer with the correctly applied read flag (dynamic layer | static layer), without writting it.

4. Most important step: Only clear the layer where the dynamic objects are in. DON'T clear the one of the static objects. That way you don't have to rewrite them to the layer ... To do so, you have to explicitely define the layer to delete within the clear collision call.

I'm using a similar approach in my simplified (for the user) collision routines in my entity system ... Due to the fact that normally only a few objects need to receive collisions it is an enormemous amount of speed gain.

[EDITED]
Edited out some inconsistencies that could lead to "faulty" structure


smilertoo(Posted 2006) [#4]
ive been wondering about that as well, seemed very wasteful having to redraw a scenery collision mask every frame.