Sign in to follow this  
Antonym

2D collisions

Recommended Posts

How do you make it work? How are 2d collisions handled? I am making an asteroids sort of game and I need to know when a missile hits an objects or an object collides with an other object and so on. Any info on how to acomplish this would be appreciated. Edit: With directx and c++ Thanks.

Share this post


Link to post
Share on other sites
I looked into those articles and well.. about the n one I have little idea how to put that into code :S... I can't get much from the source code cause I only know c++(so far).

A question I have is so the basics is check if two objects' positions overlap do you have to make this check for every object, for every possible object? How is that possible for objects that become created 'in-game'? Wouldn't it become unmanagable pretty fast? Isnt there an algorithm to work this out?

Share this post


Link to post
Share on other sites
If you have lots of objects in your game, you can use spatial partitioning to reduce the number of collision checks. One simple way to do this is to use a quadtree. That article uses the quadtree for visibility testing, but the same idea can be applied to collision detection.

Another method is to divide your objects into collision groups, where some groups only need to be tested against some other groups, and not all groups need inter-object testing.

For example, in a typical game you probably don't want to test if bullets collide with each other. So you would create a collision group for the bullets, and this group won't have inter-object testing.

Share this post


Link to post
Share on other sites
Hi,

I think you should start with something very simple and not optimized to get a basic idea of performing collision detection between game entities.

Let's say you have your game's main character and one obstacle!
You must find a way to

- Do the collision check between main character and the obstacle in each game loop.
- Create a function wich returns true if they're colliding.

Now, if you have more obstacles you need to do the collision check for all of them and not just for one:

- main character, obstacle_0
- main character, obstacle_1
- ...
- main character, obstacle_n

A good idea would be to put all the obstacles into an array, or even better in a list, so you can do the check very easily



for( int i = 0; i < OBSTACLES_AMOUNT; i ++ )
{
if( checkCollision( main_character, obstacles[ i ] ) )
{
// do collision response
}
}




Share this post


Link to post
Share on other sites
You could go for the really simple option of using a 3rd Party Library ;).

Thats what I decided to do; physics is cool but unfortuately it can take time to get all the understanding in place to produce an effective simulation.

Though if you'd like the practice its a worthwhile exercise, and you may only want simple collision detection in which case a full physics SDK might be a little bit of overkill; I wanted friction and forces in my software.


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