victorfisac / Physac

2D physics header-only library for videogames developed in C using raylib library.
http://www.victorfisac.com/physac
MIT License
432 stars 28 forks source link

How to detect collisions #31

Closed jubalh closed 6 years ago

jubalh commented 6 years ago

It seems none of the examples covers this. And I don't see the way on how to do it.

raysan5 commented 6 years ago

Hi @jubalh, just noticed this issue...

Collision detection is internal to the physic engine, no need to worry about that, just define PhysicBodies and properties to get proper physic response.

For simple collision detection, raylib already provides some functions.

Do you need any kind of advance collision detection functionality?

victorfisac commented 6 years ago

Thanks @raysan5 for your answer. Yes, the idea is to use raylib provided functions to detect collisions in a easy way in the main thread of the program (where raylib and your program code runs).

Physics are executed in a separated thread and checking collisions of the physics thread and handle the results in the main thread can be buggy and not accurated calculcated (the collision result can change between true and false a lot of times in a single frame of main thread).

raysan5 commented 6 years ago

I think this issue could be closed...

jubalh commented 6 years ago

At this branch https://github.com/jubalh/raymario/tree/new_physac I have my work in progress from some months ago. I tried to rewrite it to use the new physacs library. Unfortunately there was no git history or anything showing which were the old functions deleted and new ones added. And which ones to use now. Some stuff I figured out. Other I still have to do. Currently I dont remember the exact state of things, i just remember that the old physac seems to have used some collision detection functions and the new one doesnt have them anymore. Looking into raylib itself makes sense. Thanks for mentioning that.

In case someone wants to contribute to the raymario branch, it would be very welcome. Feel free to do so. I think once its written with newest raylib/physac it would be a great little game to show beginners how to start creating games with raylib (on linux). I'll plan yo do a youtube video or something when this is finally done. Showing how to easily install raylib on openSUSE, cloning raymario via git, developing with the gnome-builder IDE. I have this on my todo since a long time, but its just a spare time project and currently I used my time for other things. If it would have been not such a big hassle to port from old physac to new physac.. It could have been finsihed long ago ;) But such is life I guess. The long taking things are always where you dont expect them.

raysan5 commented 6 years ago

Hi @jubalh!

Actually that game is a really good introductory exercise... but it probably should be rewritten from scratch... and it requires some time...

Just in case, here there are some guided exercises I used on a Graphics Programming subject I teach, University agreed on open sourcing it.

victorfisac commented 6 years ago

I close this issue by the moment... Open it if you need it's necessary