Help optimizing 2D collision

Hello!

I’m making a small game and im trying to optimize it to its fullest. The game consists of a lot of bullets spawning while the player tries to dodge them.

The biggest issue unsurprisingly are the hitboxes.

I’m using a module called “GuiCollisionService” made by jaipack17.
The module works fine, and its spending a lot of resources so i added a simple condition thats subtracting 2 AbsolutePosition values and getting their magnitude to then check if its smaller than an amount.
Getting the AbsolutePosition value however seems to be really expensive aswell.

image

Are there any alternatives i can use instead of this? Or maybe an even better method of collision checking.

Help would be appreciated :slight_smile:

When I made my own 2D collision I made my vertices (or bullets in your case) a class, that class will have a “Position” value that the actual bullet UI will be set to every frame, that removes the problem of getting AbsolutePosition as you have it stored inside the class, you can even use it before moving the UI if you want, but better it’s better to not do so.

So i need to create and set the X and Y value of the bullet object every frame?

Yes, that worked better for me, having the position saved, updating it and then setting the bullet’s position to it.