andrew-peng-144 / js-explore-game

0 stars 0 forks source link

Solid resolution #7

Open andrew-peng-144 opened 3 years ago

andrew-peng-144 commented 3 years ago

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":

andrew-peng-144 commented 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.

andrew-peng-144 commented 3 years ago

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.

andrew-peng-144 commented 3 years ago

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.

andrew-peng-144 commented 3 years ago

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.