Open andrew-peng-144 opened 3 years ago
Better: to address the sharp corner issue, may have to just do full EFFICIENT Separating Axis Theorem between entity and intersecting edges...
Need to investigate this more.
If SAT is used, then the algorithm must distinguish between a concave and convex surface because SAT only works with convex. But otherwise, while defining complex surface on the map, SAT should work relatively well, by assuming a temportary convex polygon when the entity touches surfaces. This temp polygon is gonna be a large polygon that extends way past the opposite directoin of the normal, and the surface itself is extended a lot in both sides; essentially a giant, maybe rotated, rectangle where entity is only colliding with one side of it. After this first resolution, if it collided with surfaces that were concave, the entity likely is still in contact with one, so another check must be performed in order to resolve it. This doubles the average running time but SAT is not always running anyway. Probably need to do more testing before. Essentially this is attempting to do realistic collision resolution with any polygon.
Ignore the previous post: That method will STILL result in stuck collision (if accounting for entity's axes as well), or sharp corner issue (if only accounting for surface axes). prob just gonna do the first method and have the sharp corner issue: ensuring resolution only happens in the direction of the surface normal, but for example, a rectangle moving into a spike shape will abruptly teleport away from the center of the spike.
Doen with using 2-resolution. Diagonals work. It resolves collision on a cell-by-cell basis: takes the min resolution done by each cell, resolves by that amount, then repeats except ignores the 1st cell that was considered. Works for each diagonal case.
Can still clip thru 3 tiles tho. since its only 2-reso.
need a way to cleanly resolve solid collision with all edge shapes. For now, we are assuming the solid object is a stationary normal surface in any direction. and the moving entity can be any shape.
tentative: "n-resolution":
for each intersecting surface, find the displacement that the entity must move in order to not intersect with that surface anymore, then move the entity by the smallest displacement out of all the intersecting surfaces.
Then repeat this until the object is not intersecting any edge anymore, or after n iterations. The min disp should handle all convex, and the reptition should handle concave cases.
This method ensures entities only get resolved in the direction of the intersecting normals.
Behavior: edges of the same normal next to each other won't have any "stuck" behavior when moving diagonally against them, so certain tiles on the tilemap can be defined as always having a edge of a certain normal, leading to faster level creation. But as a drawback, sharp corners may have glitchy behavior b/c it moves the object in an oblique direction to resolve it, e.g. see block on a spike.