C Board  

Go Back   C Board > General Programming Boards > Game Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-26-2002, 10:37 PM   #1
l'Anziano
 
DavidP's Avatar
 
Join Date: Aug 2001
Posts: 2,618
Question collision detection

I was working on my collision detection for my DBZ clone of Liero today, and I was presented with a problem. For any of you who know Liero (which is much like Worms), you will know that the map is displayed like this:

Background bitmap
"Dirt" or deformable terrain bitmap
"Rocks" or impassibles

The background is a single bitmap blitted onto the screen. The "dirt" is also a single bitmap blitted onto the screen, but with several spots where it is transparent, so you can see the background, and the dirt can be deformed, so more of the background shows.
The rocks cannot be changed. That is also the order in which things are blitted onto the screen.

Now, keeping in mind how the map is displayed, here is how it is done in my DBZ clone:

Background
Foreground

My game does not have a deformable foreground as of yet like Liero does, but basically everything in the background is the background, and everything in the foreground can be collided against.

Now how would you do collision detection? Lets say you have a 20x25 character moving along who bumps into a wall while moving right along the screen.

You cannot just check the coordinate (20, 0) for a collision, because the collision could occur at (20, 24)...at the bottom of the guy....but you cant check just (20, 25), because the collision could occur at (20, 0), and you cannot just check (20, 13) (the middle right) because the collision could occur above or below that....

That means that you must check every coordinate of (20, x)...where "x" is greater than 0 and less than 25.....

That means you must make 25 comparisons every time the guy moves right or left.....which could be happening very often....doesnt that seem a bit taxing on the computer to make 25 comparisons every time the guy moves right or left.

Lets say you move to the right for 1 second...which is very likely and very possible....and lets say you are getting 50 fps...that means you must do 50x25 comparisons....which is 1250 comparisons in just 1 second of moving to the right....not to mention having to do all the other stuff like blitting graphics, etc...

How much do you think that would tax the game? Is there a better way to do the collision detection then that? I'd like any input I can get....thanx...
__________________
My Website

"Circular logic is good because it is."
DavidP is offline   Reply With Quote
Old 04-27-2002, 12:02 AM   #2
Registered User
 
Join Date: Aug 2001
Posts: 403
rectangle test??

i think you could just use a simple rectangle test.. read this article
http://www.gamedev.net/reference/art...article754.asp
cozman is offline   Reply With Quote
Old 05-11-2002, 01:31 PM   #3
Registered User
 
Join Date: May 2002
Posts: 132
Since you are using (I assume) 2d bitmaps, then another simple solution could be for your to determine the center co-ords of your character that is being moved. Then have a struct (or perhaps just ints if that will suffice for you) that holds the fartherest right (how many pixels towards the character's right) it's own body goes out. This isn't including the entire bitmap size, just the body. So say your using the 20x25 character, but the character itself could be boxed within 18x20 pixels. And say the middle of bitmap could be at the 10th-x-pixel and the 12th-y-pixel. This means that you could perhaps have a 9 left-x value and a 9 right-x value (or something similar... these are just quick values for the example). And the left-y value could be 10 and the right-y value could be 10 as well.

So if the character is moving right, check the middle x co-ord of your character + 9 versus objects in your character's path. If an object is less then this value (the objects x co-ord) and higher then your character's middle x co-ord minus 9 then stop the character from going any further towards the right. Or you could go a little further and do some more checks now that you know that the object is within this area and check to see if the object is touching your character YET, cause in reality it might not be. Or you could use the first method and just stop the character where it is.

And you could use this type of checking for if they move up or down. Its a simple method, and a lot less checking has to be done.
tyouk is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with AABB Collision Detection. Shamino Game Programming 10 03-30-2009 07:00 PM
Collision Detection Problems Dark_Phoenix Game Programming 1 12-17-2006 03:25 PM
Collision Detection Grantyt3 C++ Programming 3 09-30-2005 03:21 PM
bounding box collision detection DavidP Game Programming 7 07-07-2002 11:43 PM
boolean algebra / memory manipulation / collision detection DavidP Game Programming 4 05-03-2002 09:40 PM


All times are GMT -6. The time now is 06:11 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22