Skip to content

pfirsich/wuzy

Repository files navigation

wuzy

Collision Detection Library

Almost always when I make games I come up with some ad-hoc stuff for collision detection, which often works, but is always a huge pain and takes too much time in game jams.

I feel like either you bump a few spheres and AABBs into each other with your own code OR you have to go super big and use a full blown physics engine. This is supposed to fit into the gigantic gap inbetween.

This is supposed to be the least amount of code that lets you control a character in a level.

It will just do collision detection and resolution, no kinematics or dynamics. You can just create colliders and bump them into each other and get vectors that resolve the collision. It also does ray casting.

Most of the games I made were not made with any of the big engines, so I only used a proper physics engine a few times and I hated it quite a bit. It's very restrictive that most of the time you cannot set the position directly (which makes sense, but it is restrictive none the less) and I firmly believe that for most games the optimal physics have nothing to do with real-world kinematics and dynamics, so this library handles collision detection and resolution. No accelerations or forces, no constraints or anything of the sort. Maybe velocites if I ever introduce continuous collision detection.

Something like this: https://docs.godotengine.org/en/stable/classes/class_kinematicbody.html

This is not made for AAA games and millions of colliders. This is for games that hobby gamedevs might make in a gamejam or the average indie game you can get on Steam. It tries to be obvious and easy to integrate. It's supposed to provide the minimum amount of collision detection and resolution you need to make a game (that is not super focused on physics).

Integration

wuzy provides a C header file (include/wuzy/wuzy.h), but is written in C++20. All dynamic allocations are obvious and can be controlled via a custom allocator. Only a few operations dynamically allocate at all (such a creating a new AABB Tree or preparing memory for queries) and it's possible to do all of that at initialization time.

If you don't want to use CMake, you can build src/wuzy.cpp yourself with std=c++20. It should compile with -Wall -Wextra -pedantic -Werror -Wconversion and -fno-exceptions/-fno-rtti, if you need them.

There is a C++ wrapper in include/wuzy/wuzy.hpp and a few examples in examples/.

Architecture

wuzy uses GJK to test whether shapes overlap and EPA (Expanding Polytope Algorithm) to generate contact information (collision normal and depth). To speed up queries there is also a AABB Tree.

I plan to add a high-level API which should should reduce the API surface to the essential and allow usage without understanding any of the involved algorithms at all.

Usage Notes

If you need collisions with meshes, like levels, just create a separate collider for each triangle of the mesh. For static level geometry I would advised to create a separate AABB Tree.

TODO:

Maybe Later

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published