Collision detection has always been a big issue because of how expensive it is, I've heard. That I'm not worried about, a skim of the N+ tutorials has shown me that a grid system will work nicely for that. My problem is figuring out how to bounce off objects/kill overlap by applying halved inverse differences to three objects instead of two. My code is as follows:
for (a = 0 through maxPlayers) {
for (b = a through maxPlayers) {
if (a.collides(b)) {
bounceOffEachother(a,b);
}
}
}
...where bounceOffEachother will take the difference between them, find the axis of least resistance, and push them away from each other on that dimension to create a slide or push effect. Everything is cube shaped, so this works out well.
So, for trying to fix this, I wanted to get all collisions, then apply all the bounces...
for (a = 0 through maxPlayers) {
Player collidedWith[maxPlayers];
int collisionSlot = 0;
for (b = a through maxPlayers) {
if (a.collides(b)) {
if (collisionSlot < maxPlayers) {
collidedWith[collisionSlot] = b;
collisionSlot++;
}
}
}
for (c = 0 through collisionSlot) {
bounceOffEachother(a,c)
}
}
And yes yes it should be collidedWith[c] and I should be using playersPlaying[a] or something but this is pseudocode so I'm only doing what I have to for you to understand what I'm talking about.
So, my problem is, this technique still isn't working. I'll have my one dimensional bounces only apply to one collision still. Really, I'm not just using this for players, but also for walls, so if you hit two walls at once, only one of them has their collision create a bounce... meaning a row of walls doesn't work. So, any suggestions? I like having a two element bounceOffEachother function, but is that just not feasible for what I want to do?
Thanks guys!