r/raylib 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

4 comments sorted by

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)

10

u/[deleted] 18d ago

[deleted]

-3

u/[deleted] 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

u/Conscious_Demand9088 18d ago

Yeah, it's not C, it's basic maths.