GDC-WM / 2DGame2021

Has a very nice backend structure but no real gameplay (yet?)
MIT License
1 stars 1 forks source link

Enable collision detection between entities #8

Open aaronamk opened 3 years ago

aaronamk commented 3 years ago

Likely most will be circle collisions

BlastWind commented 3 years ago

Insight: On every frame, we loop through dynamic actors (characters, traps, teleport door, etc) and detect for collision. Here's my quick thought on the structure: Each actor has a onCollide(&Actor otherActor) method that runs conditional code based on what the type of the other actor is. There is a contact listener that calls the onCollide method for the actors.

See how Aaron implemented the idea using a sexy listener object in Parryt: https://github.com/GDC-WM/Parryt/blob/main/src/contact_listener.cpp

BlastWind commented 3 years ago

Resources: 1) Collision detection and response (starting page 173). This whole book is pretty good.

BlastWind commented 3 years ago

@aaronamk what are the pros and cons of using circles, and of using rectangles?

aaronamk commented 3 years ago

Here's a very relevant file from the homegrown physics branch of Parryt. For whoever completes this issue, please refer to this for how to implement the actual math of the collisions.

pros and cons of using circles, and of using rectangles

There's no real pros or cons. Both systems are very simple to implement and we will likely have to use both. For each entity, just use the shape that most closely approximates the shape of that entity. Walls will be rectangles, characters will likely be circles (for a top-down view game), etc.