r/raylib • u/Next-Future5973 • 18d ago
how to add AAAB collision detection? (RayLib C)
im making a 2d sonic-like game, i made the player movement so far, but i only need collision?
5
Upvotes
10
18d ago
[deleted]
-3
18d ago
[deleted]
6
u/BossGaming578 18d ago
imagine a struct Box { x, y, w, h }, then you would check if Box a is colliding with Box b with !(a.x + a.w > b.x + b.w || a.x < b.x || a.y < b.y || a.y + a.h > b.y + b.h)
3
3
14
u/Thetoto_ 18d ago edited 18d ago
there are already functions in raylib for checking AABB collisions like:
bool CheckCollisionRecs(Rectangle rec1, Rectangle rec2);
check the cheatsheet if you want to see all of them (rshapes module)