Alright, so lemme try to work this out. I do some raytracing with the object's velocity vector, find the first thing it intersects and the normal of the collision (which would just be a horizontal or vertical line with AABBs, regardless of the ray angle, I think?), then zero the vector along that normal I calculated. So in the case of moving down and to the right, my vector would end up pointing straight to the right instead. Then I repeat until there are no intersections with the ray.
Yup, that's the idea.
Also, I assume that zeroing the vector along an axis involves vector multiplication (dot product or cross product), but I'm not sure of the exact operations I should be doing here. It would be extremely useful if I could get this working with slopes.
You can multiply it by the "swap" of the normal. This is usually what we mean when we talk about transposing a vector. You can go into the math, but in programming terms, it boils down to this: if the normal vector is {x, y}, then you want to multiply the velocity vector by {y, x}.
You can see how this achieves the effect.
EDIT: also I just realized I don't even know where to trace the ray from. Should it be from the AABB's corner which is pointing in the direction of the velocity vector? This might be more difficult than I thought.
There's a really useful thing called the "Minkowski sum". In the context of collision detection, instead of checking whether both AABBs collide by iterating over the corners, you collapse one of them down to a point, then add the width and height to the other one, and check whether the point is within the new, expanded rectangle. I'd do the velocity vector ray trace from the point.
Here's a relevant stackoverflow:
http://stackoverflow.com/questions/16198437/minkowski-sum-for-rectangle-intersection-calculationIt's kind of annoying to find the normal of a slope under an AABB system, but you can still do it... it just means storing more data than you are presently (or extrapolating the slope from the pixels). With an AABB system you just don't know enough to properly find the normal of a collision surface. You could do something real janky like flag the stairs/ramp as a diagonal, assume a 45 degree slope, find the normal of that... but it's not really clean. Basically your code would look like:
if(GetCollision(entityA, entityB)
{
if(entityA.isSlope || entityB.isSlope)
ResolveJankyCollision(entityA, entityB);
else
ResolveAACollision(entityA, entityB)
}
If you're just working on a 2D platformer that doesn't need ultra robust physics (i.e., convex polygon collision detection), this is probably what you want to do. But I'd focus on getting regular AABB working first before implementing special cases like this.
Someone who's better at math than me, feel free to chime in. I am only distantly familiar with what I'm talking about.