Question: I’m working on a platformer game and I can’t figure out how to add a collision detection to the game since it’s a complex circle-rectangle collision. I want the ball to stop when it touches a tile and before it can cross tiles. I also don’t want it to go beyond my screen, I can do it myself too so not main issue.
I’ve tried:
Several basic collision detection codes and altered them to fit my need but I’m unable to think of a way to do it.
I have created a simplified array, where body A represents red circle ball and B represents all the tiles.
I’ve also tried codes from several repls and tried creating some myself.
Collision detection is at the end of the code. My code may be complex to understand and hence you may need to fork my repl to debug it. Thanks in advance !!
I’m not sure what the issue is, but I made a simple demo of a circle-rectangle collision function here (and here’s a demo of that collision detection in action). (I often prototype/test basic stuff on KhanAcademy.) Does this help?
@MarioX, how can I use friction, gravity to detect collisions? Though I don’t need to use any libraries I found another way around, I am going to detect collision whenever character moves, hope it works.
Your code looks great, just my implementation of it is different. I’ll mark this as answer as soon as I am able to manipulate it successfully. I may reach out to you again if I need help regarding same, Thanks for help