brotherhood-of-recursive-descent / tankism

top down panzer game written in golang and ebiten
GNU Lesser General Public License v3.0
2 stars 0 forks source link

objects react to collisions (stop movement, explode, remove entity, ...) #38

Open co0p opened 2 years ago

co0p commented 2 years ago

currently objects move through each other. There should be a basic collision detection system, that reacts when there was a collision detected

AABB: https://github.com/co0p/foodzy/blob/c9a8a145f264da217b0a9af2f48d588e712c8418/collisionSystem.go#L71

co0p commented 1 year ago

turns out AABB is not sufficient when 2d objects can rotate ... see https://stackoverflow.com/questions/563198/how-do-you-detect-where-two-line-segments-intersect and for more details:

https://gamedevelopment.tutsplus.com/tutorials/collision-detection-using-the-separating-axis-theorem--gamedev-169

co0p commented 1 year ago

test cases:

Image

co0p commented 1 year ago

Example on how to do the math with points and rotate matrix... https://math.stackexchange.com/questions/126967/rotating-a-rectangle-via-a-rotation-matrix

co0p commented 1 year ago

@jevbelikov see https://github.com/brotherhood-of-recursive-descent/tankism/blob/master/lib/collision/collision_test.go for the first test on collision AABB style

co0p commented 1 year ago

Maybe helps: To get Rx(\theta) in right-handed coordinate system, replace the angle \theta with negative \theta. Then apply the following rules.

cos(-\theta) = cos\theta sin(-\theta) = -sin\theta