Crafty icon indicating copy to clipboard operation
Crafty copied to clipboard

Collision checks - use rectangle intersection where applicable

Open mucaho opened this issue 10 years ago • 0 comments

As stated in 932 custom hitboxes are often plain rectangles. If both Collision entities have a plain rectangle as their custom hitbox perform rectangle intersection instead of SAT. Overlap and normal should be easy to calculate I guess for simple rectangles.

Approach#1 We could detect that on initialization of custom hitbox in collision(...) and add a flag property to this.map. Rectangle intersection gets executed in hit iff both hitboxes are plain rectangles. However, as soon as entities get rotated we have to invalidate the flag and use SAT instead.

Approach#2 Accept rectangle (_x, _y, _w, _h) as parameter to collision(...). Save it as this.rectMap and handle it in collision checks. Sounds better than Approach#1 imo.

mucaho avatar Jul 20 '15 22:07 mucaho