Problem: Enemies that are affected by gravity fall through the floor when falling at higher speeds!
— I have no problems with flying enemies
— I have no problems with RIGHT & LEFT & TOP Collisions
What I do for right, left and top collisions is simply use while instead of if. It works out just fine, but when it comes to bottom collisions it crashes in an infinite loop! That’s why I can’t use while on bottom collisions. Only if.
The problem is that the code doesn’t react in time to push the enemies away because I’m not using while. It’s absolutely fine when the enemies fall a short distance, but as soon as en enemy falls off a high ledge, it will fall through the floor due to higher falling speeds.
I tried limiting the fall speeds but it’s an artificial way to fix it and it looks like they are on the moon. Which is not natural. Is there a way I could counter high speed collisions without using while?
Is there actually a way to use while for bottom collisions?
Depending on where your code is executing the collision and the movement for the gravity you might be moving past a hit box. If you were to put in code that looks at a vector and then check for the nearest colliding object you could check if the object would fly past the colliding area before a hit test would execute.
That or you can test to see if the objects are over lapping at some point and then move the stray object back to a certain position.
Just throw in some trace statements for the hit box tests and see if your high speed objects are flying past without it activating.
Perhaps the bottom collision difference is so exact that the rectangles still intersect, thus creating an infinite loop. Have you tried adding a difference of .5?
Thanks people. I figured it out. The problem was that it was in another loop which did a calculation of each block, once I took it out of that loop, it was perfect.