From which corners do you start the lines? |
The map is a series of line segments. Each line segment has 2 endpoints. Those endpoints are all "corners" from which lines are projected.
I didn't draw all 3 projected lines in figure 2, i only drew the relevant one.
How do you deal with cases where that line would intersect with the player, but no actual collision happens (moving towards a corner, but not into it) ? |
This never happens. The projected line is equal to the motion vector (just reversed so it's oriented in the opposite direction). If the line doesn't reach far enough to intersect with the player, then the player is not moving far enough to reach the wall.
Anyway, it seems needlessly complex |
Perhaps it's just how I'm explaining it. I find the concept to be quite simple =x
Although the implementation does get a bit complicated, admittedly. But if you can show me an effective way to do collision detection that doesn't get somewhat complicated (and actually works in all cases), I'd be happy to hear it. AFAIK it can't be done.
I think you could do it in a simpler way. Traverse through every point and check if it's in the area limited by the red lines and player's shape ("Figure 1B"). |
This kind of defeats the whole point of the line approach. If you're only checking based on the state of the object after the move and not the move itself, then tunneling becomes a problem. Fast moving objects can go right through those kinds of checks, whereas a line based approach will always stop the object appropriately no matter how fast it's moving.
Besides, if you only check to see if the object is "in the wall", it's kind of already too late. How do you eject them from the wall? Of course you'd have to move them backwards until they're no longer in the wall, but by how much? The fundamental principle here is you stop the object
before it gets "in the wall".
Also, how will you do the object/object collision and what's wrong with current mechanism? |
Object/object collision I'm planning to do the typical way with hit boxes. This reintroduces the issue of tunneling, but I haven't really thought of a way to avoid that yet.
I wonder if I could apply the same line-based techniques here. To be honest I haven't really given that much thought.