Simple fast 2d AABB collision system

Hi Everyone,
i’ve been making my TD game for about two years, and it’s going really well, except the collision detection.

i’ve been trying to make a collision system in unity that could handle about 800-900 objects in one level,
and it’s not working.
at first I tried OnTriggerEnter based, that drops frames after about 90 colliders.
so i decided not to use any of Unity’s Physics components in my game, but i’m failing to create a collision system that works well.
I tried ECS in Hybrid mode as well but to no real success.
even with grid based spatial partitioning and only checking for box collider intersections, i’m dropping below 60FPS at 200~ objects.

If you have some insight, or a ready made system like that I would be very happy to hear from you,
this is risking my whole project right now :\

create your own collisions, just using math and bounding boxes

each object only checks for collisions on its movement script
each object only compares with objects that are near it
keep a dictionary that contains the positions of every object in the scene for fast access

I created it for my game and it can handle 1000 characters on screen, though i use vertical sync so dont know if it goes higher than 60fps which is the maximum for my game

Thank you for this.

I am super curious to see how you did it.
Would you mind showing the code or reaching out to me on discord (id in original post) ?
Would really appreciate it

its too long to post, it was a lot of work to do it xd theres 10k+ lines of code

the idea is that when you give a command for something to move, it checks the dictionary to see which objects are near, and then loops throught them with bounds intersect to predict if the movement will generate coliision. If there will be collision it tries to generate movement on the collided object which chains until there is no colision = everything is allowed to move, or finds collision = nothing in the chain can be moved.

I do the same for gravity, if there are no collisions below the feet then I add y speed to fall etc

I see,
And this is in monobehavior, not ecs?

Github link could also be good :wink:

yes i am not knowledgeable enough to use ecs, its just normal c# object oriented

from what I’ve heard ecs is much superior in performance, but i wont dare to use it since there are very few people using it, hence less information readily available, and im not good enough to just find everything by myself