victorfisac / Physac

2D physics header-only library for videogames developed in C using raylib library.

Home Page:http://www.victorfisac.com/physac

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Knowing whether collisions have happened

ncot-tech opened this issue · comments

(I found the closed issue from 2017, but this query is a little different)

I'm just using Physac by itself, with SDL 2. So far I have things that move and collide quite nicely.

While I understand collisions are internal to the engine, is there a strategy to know whether two things have collided? For example suppose I have a rocket moving across the screen and it hits a target, how can I tell the collision has happened so I can make some game logic run?

You should calculate it by yourself defining an area of collision (different to the one defined in PhysicsShape struct or reuse the same one). The way to detect that two physics bodies has collided is defined in the CheckCollisionCircleRect and the other functions.

But I think it's simpler if you detect it by your own using some data from the structs and do it in the main thread so you can apply whatever logic you want... raylib provides functions to check collisions between shapes just passing the shape properties as parameters.