Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411977 Posts in 69438 Topics- by 58486 Members - Latest Member: Fuimus

June 15, 2024, 01:25:47 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Spatial Collision Slicing / partitioning
Pages: [1]
Print
Author Topic: Spatial Collision Slicing / partitioning  (Read 962 times)
Trevor Dunbar
Level 10
*****


Working on unannouned fighting game.


View Profile
« on: June 14, 2010, 05:49:16 PM »

Whats the best way to slice your level up into small chunks to be processed and checked inside collision and stuff? Can anyone give me a bit of implementation inside c#?

Also giving partitions their own mini-partitions to speed up collision checks even more?


Also what happens, when say, an enemy moves from inside one partition to another?
Logged

Toucantastic.
Alex May
...is probably drunk right now.
Level 10
*


hen hao wan


View Profile WWW
« Reply #1 on: June 14, 2010, 10:50:39 PM »

Whats the best way to slice your level up into small chunks to be processed and checked inside collision and stuff? Can anyone give me a bit of implementation inside c#?

There is no best way, it depends on what you need. For 2D, the simplest is probably just a regular grid of cells - this is suitable for smaller spaces or if you are already working to a grid e.g. tile-based games. You could use a quad-tree if you have objects of greatly-varying size or if you have a really large space and only need to store data where there are objects. Or you could divide up space intelligently if you have a rooms system for example, so that each room has its own collision list or grid.

Also giving partitions their own mini-partitions to speed up collision checks even more?

It can do yes, depending on the space you're using and how deep your layers are. For a quad-tree, where each square can have up to four children (each of a quarter size of the square), and each of those children can have four children etc., traversing the tree can become a massive pain in the neck. And also if you have objects overlapping boundaries, they can end up in some of the very large boxes near the bottom of the tree and end up being tested against things that are miles away.

Also what happens, when say, an enemy moves from inside one partition to another?

Entities could be present in many partitions at once, this avoids entities moving from one partition to another and suddenly appearing right in the middle of another entity. But typically each box would have a list of present entities, and when an entitiy leaves the box you remove the entity from the list and add it to whatever new box it has entered.
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #2 on: June 15, 2010, 02:16:17 AM »

There are several techniques for this. The most popular are known as spatial-hashing (tiles, as descibed above), and quad/oct trees, possibly "loose". (there's actually even more tree variants I could go into). If implemented correctly, such a broadphase can be an independent part of your system, so you can swap implementations.

Which is best depends on the factors of your game - how consistent in size are objects, how many are stationary, etc.
Logged
DeadPixel
Level 2
**



View Profile WWW
« Reply #3 on: June 15, 2010, 08:44:46 AM »

http://www.sgtconker.com/2009/10/spatial-hashing-implementatio-for-fast-2d-collisionsplaceholder/

Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic