1
Graphics / Re: Collision detection between sprite and shape
« on: May 04, 2021, 11:00:09 pm »
Thanks a lot eXpl0it3r.
I know and understand that pixel perfect collision detection is rarely needed, it just kind of bothered me that I could clearly see that the player died even if an actual collision hadn't occurred. Could definitely be because I know that is the case though and not a real problem
The game in question is a very basic attempt at reimplementing the class Pang! game that I started years ago and only recently had a look at again. The code is shared under the GPL here.
There are tons of known issues with the code and of course even more I don't know about, but it's mostly just a way for me to try and play with writing code in a field I'm not very experienced in, so please keep that in mind if you feel like you have the courage to read the code
The collision detection I wanted to improve is currently happening in the main function (it shouldn't be there, I know) and is simply using the intersects member function.
It is the indeed the same code from the SFML wiki I've tried using. I thought it would be more or less "drop in" which is why I'm a bit puzzled.
Considering the actual problem (improving collision detection a bit), I've thought about using some basic geometric calculation to figure out if the circle intersects with the (player) rectangle instead. Maybe that would be a better solution?
Thanks a lot once again. You're input is most appreciated.
I know and understand that pixel perfect collision detection is rarely needed, it just kind of bothered me that I could clearly see that the player died even if an actual collision hadn't occurred. Could definitely be because I know that is the case though and not a real problem
The game in question is a very basic attempt at reimplementing the class Pang! game that I started years ago and only recently had a look at again. The code is shared under the GPL here.
There are tons of known issues with the code and of course even more I don't know about, but it's mostly just a way for me to try and play with writing code in a field I'm not very experienced in, so please keep that in mind if you feel like you have the courage to read the code
The collision detection I wanted to improve is currently happening in the main function (it shouldn't be there, I know) and is simply using the intersects member function.
It is the indeed the same code from the SFML wiki I've tried using. I thought it would be more or less "drop in" which is why I'm a bit puzzled.
Considering the actual problem (improving collision detection a bit), I've thought about using some basic geometric calculation to figure out if the circle intersects with the (player) rectangle instead. Maybe that would be a better solution?
Thanks a lot once again. You're input is most appreciated.