I'm trying to replace my old integer based movement and collision system with a vector system, because its more precise and more flexible.
I want to implement wall sliding, such that if a player hits a wall diagonally, he will still slide along it.
The problem I'm running into is that all my hitboxes are just that- boxes. I use Rectangle2D
to represent everything, and I don't know how to find the right normal.
If the blue box is the player colliding with the red box wall, I'm not sure how to find the correct normal to subtract from the player's movement vector. Since the wall has 4 possible normals, I'm not sure how to quickly get that normal. I think I can do it using a bunch of distance tests to get the nearest two points, but that seems inefficient and possibly error prone.
Is there some better, faster way than just testing each point for distance and using the nearest two to create my vector?