ARTICLE AD BOX
I'm programming a very simple 2D physics engine for a game. The engine is designed to be pretty fast so at first I was hoping to use axis aligned bounding boxes for everything.
The physics engine calculates obstructions ahead for every pixel the rectangle moves. If it finds obstructions ahead, it doesn't move it, and stops it. To do the checking, I just looped through all the game objects that are solid and checked if the rectangle was next to them. (one pixel off from the rectangle so they never truly "touched" and both get stuck!)
Well, the collision function didn't work. The collision function I used was the typical one you find online: Find out if they're not intersecting and negate the result.
Interestingly, and this is the crux of the whole question, the collision function only worked for the top and left sides of the rectangle. Please let me know how I can get the bottom and left to collide!
After rectangles didn't work, I decided to switch to lines. To check if the lines intersected, I used this algorithm (with a few small changes) since I figured it would be battle tested and fast coming from a competitive programming site. (If you're wondering, I later also tried an algorithm on geeksforgeeks and it produced near identical results.)
This time I constructed both actors out of 4 lines. If the actor is moving right, the right sensor is checked. If up, the top is checked, etc.
Anyway, it produced the same results :( The solid object, now constructed out of 4 lines, only has 2 working lines, the top and the left. The right and the bottom do not work at all. Does anybody know why this is happening and how I can fix it?
As for game engine / framework, I am using open frameworks but essentially all the code here is mine other than the line detection function and some wrapper stuff
