Question:
How can I reduce the amount of collision detections?
Goal:
What I want to do is to check a large dictionary with tile data for collisions with an entity, fast. All tiles and entity's use a rect for collision. I mainly want to reduce the amount of collision detections. I know how to do collision detection.
Code/what I have tried:
I have tried to loop through all blocks(with a for loop) and check collision for each one(if it is a solid block). This method is too slow to do for every entity.
One thing I could do is split groups of blocks into chunks and detect collisions with chunks first, then check collisions within the chunks the entity is colliding with. I seems unnecessary as I won't be using chunks for anything else.
One block looks like this, {(0, 0):["block_name", pygame.rect((0, 0), (64, 64))]}.
Research:
I have searched for this everywhere and I can't find anything.
Please tell me if I need more detail.