Like this:


The player is only holding right, however the character still moves up a bit to go around an obstacle.

My current collision system has access to:

  • The entity's previous position
  • The entity's current position
  • The entity's (axis-aligned) bounding box
  • All the obstacles and their (also axis-aligned) bounding boxes

Also it proccesses each axis separatelly.

How can I implement this?

  • \$\begingroup\$ Can you elaborate on how it "processes each axis separately"? I suspect the solution lays in the specifics of that implementation. \$\endgroup\$ – Seth Battin Oct 11 '13 at 20:34
  • \$\begingroup\$ @Seth If neither the x and the y in the movement vector equal to 0, the function does nothing but call itself again, first changing the movement vector y to 0 and then changing the movement vector x to 0. I don't really like this approach, but it's the only one I could get to work perfectly. \$\endgroup\$ – Gerardo Marset Oct 11 '13 at 20:59
  • \$\begingroup\$ (or at least very relevant) \$\endgroup\$ – user1430 Oct 12 '13 at 5:05
  • 1
    \$\begingroup\$ @JoshPetrie Maybe closer to this one? Top Down RPG Movement w/ Correction? \$\endgroup\$ – MichaelHouse Oct 12 '13 at 6:10

Traditionally if you're travelling parallel to the axis of a box, traditional collision handling won't make you go around the corner like that. That's because there's no local information on whether you should go around by going up or by going down.

I see two obvious options:

  1. Local approach - make the collision shape a box with bevelled corners, e.g. a type of octagon. Therefore it would naturally (depending upon implementation) slide along the corner because it's a 45 degree angle.
  2. Global approach - when a collision occurs decide by some heuristic which way to go. For example pick the shortest path to the opposite side of the box.

To slide along an angle nicely, take the attempted movement vector and subtract the component in the direction of the normal of the box.

