View Full Version : Collision Detection Grid
Polaris666
June 20th, 2010, 02:44 PM
In the last game I made, I managed to implement a grid in order to avoid checking for collisions that could never happen.
It worked pretty well, but I realised that the objects can't be larger than a cell on the grid, otherwise the collisions might not work properly.
Any ideas on how I could overcome this problem while maintaining the relative simplicity that a 2D grid offers over other more complex broadphase collision detection methods?
Freshmaker
June 20th, 2010, 02:55 PM
Increase the grid size or change the algorithm. I often see hierarchial grids or sort/sweep suggested for dynamic objects (which I assume is what you're testing due to your initial choice).
Polaris666
June 20th, 2010, 08:32 PM
Bleh, screw it. Been trying to wrap my mind around this thing and it really doesn't look like you can have a standard grid handle objects bigger than a cell while retaining speed or simplicity. I would need to change my system completely.
I rather work with what I already have and design something cool around the limitation.
Valaran
June 20th, 2010, 10:45 PM
Whats wrong with doing a simple check if the object is X amounts bigger than a cell and then test adjacent cells aswell? (If it is indeed bigger) I dont think this would pull you down a lot in terms of performance.
vonWolfehaus
June 22nd, 2010, 02:17 PM
To get around this problem I assign the same object to multiple cells. Inefficient but it works. Also, I split up sprites into segments that are smaller than the a grid cell--just remember to assign the game object a unique id that each segment has so that it doesn't try to collide with itself. The unique id also leads nicely into inverse kinematic sprites.
Polaris666
June 24th, 2010, 12:47 PM
I thought about adding the same object to different cells, I didn't test it, but I guessed it would have been inefficient, thanks for the clarification on that one.
Indeed, after pondering the issue for a while, I figured that the best thing to handle bigger than a cell objects, is split them into smaller entities, that should work just fine.
DrRobot
July 11th, 2010, 05:33 PM
I think what you want is called a Quad tree (http://en.wikipedia.org/wiki/Quadtree)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.