Archived

This topic is now archived and is closed to further replies.

[java] making collision checks more efficient

This topic is 5671 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey hey chaps, I''m becoming quite a regular here now. The worst bit is that I''ve got even more questions to come. Anyway, on with the next one? When doing my collision check between a player and all the platforms in a level how do I prevent the engine checking every single platform? How do you efficiently filter out the ones that aren''t going to be of relevance? I''ve got the collision working, it''s just that it checks ever single platform repeatedly which is ludicrously inneficient. Any suggestions?

Share this post


Link to post
Share on other sites
Hi a good solution might be to use one of the many types spatial partioning trees, like quad trees, bsp,etc.
There are plenty of docs on these.
Can''t really say more without some more details about what your doing.
Harley.

Share this post


Link to post
Share on other sites
knackers. I forgot to mention that I''m only dealing with a 2d platform game. I''ve currently got a screen full of blocks to jump onto (stored in an array). With every player update I check all the blocks for collision. It works fine but I was thinking that if I were to add scrolling and introduce numerous more blocks, how could I limit the collision checks to only those in the general area. Should I check every blocks location first and then the ones that are close or is there a more efficient procedure.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You have your current position, so convert that into the tile position by dividing by the tile size. That''ll give you the current tile in your array that you are over. Then, depending on your player dimensions and tile dimensions, check all the tiles in the array surrounding that point (like, say, the tiles above, below, left and right one tile).

Depending on your player movement you may be able to simplify it even more to just the tiles infront of the character...

Share this post


Link to post
Share on other sites
You could separate the level into blocks and provide a list within each block of the platforms that are partially in that block.

Then when the player is moving, you only check the blocks that the player is inside or overlapping.

I used that method in a space shootemup - I split the playfield into a 10x10 cube array with linked list references to all objects within each cube, and checked only those collisions against each other, and I got a 3x frame rate increase (on a 200 MHz machine, a few years back)

Share this post


Link to post
Share on other sites
I recently coded a simple scrolling jump''n''run game and encountered the same problem. I was thinking about taking the approach explained by waverider but in the end, I just checked if the object in question was on the screen before performing coll detection. If it''s fast enough for you, you might just keep it that simple.

Share this post


Link to post
Share on other sites