Sign in to follow this  
Fukushuusha

2D Strategy game unit/map problem

Recommended Posts

Hello there. I am building a 2D strategy game, with a tile based map system. A problem has arisen though and I am at a loss. It is bout collision detectionof the units. At first I thought to check if each unit collides with all others in the main loop and then draw them all. Well that is completely wrong ofcourse since it will make too many checks in every loop and also by correcting the position of a unit while colliding with another unit there is the unfortunate possibility of sending into another unit's area which has already been checked ... in 1 word MESSY. Last time I implemented collision detection was in a space invaders game, it was easy back then. Just check if the player collides with any of the aliens, nothing more. But here I am a little confused. I think that somehow I have to make each unit check for collisions on its own, in its sourrounding area ... but I have no idea how to implement it. I would be really grateful for any tips of any kind.

Share this post


Link to post
Share on other sites
Hi,
Well first you need to come up with a way of storing and processing of your objects there better this is done the faster it will run.
Things you will need to look up are 2d arrays, link lists, trees and others.

I used a 2d array a grid and put all the objects it that
then you can use a array entry for look up like this
Object = Map[125][100];

then when you want to do collision you get the objects current pos and then use its neighours cells for the collision its only a loop and array look ups fast

Share this post


Link to post
Share on other sites
Thanks to both of you. I am currently looking quad trees up. I think that this is the answer I have been looking for. I plan to implement one in my game since it will allow me to check only each units surroundings and not overkill it by checking each unit with each other unit.

EDIT: Dancin fool thank you! I think that's it. I looked it up and it all makes sense now. It is the perfect way to represent 2D space. THANKS :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this