2D Collision detection.
2D Collision detection.
2D Collision detection.
2D Collision detection.
2D Collision detection.
2D Collision detection. 2D Collision detection. 2D Collision detection. 2D Collision detection. 2D Collision detection. 2D Collision detection. 2D Collision detection. 2D Collision detection.
2D Collision detection. 2D Collision detection.
2D Collision detection.
Go Back  Xtreme Visual Basic Talk > > > 2D Collision detection.


Reply
 
Thread Tools Display Modes
  #1  
Old 08-29-2009, 03:30 AM
vcand vcand is offline
Newcomer
 
Join Date: Dec 2003
Posts: 5
Default 2D Collision detection.


I have not been able to find the exact answer I am looking for. I am making a really cheesy game and I'm having some problems with collision detection. I know there are probably many "better" ways to do this, but I'm not that advanced in game programming.

I made the background of a form my map (its just a bitmap of the land and objects). I am trying to find a simpler way to enter the coordinates and have it check for collision. Right now I am moving my mouse over the form to get the coordinates of the objects:

Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.Caption = X & "," & Y
End Sub
Then I'm taking those points and using if statements to determine if the future location (location + ___) would be <> the top and <> the left coordinates. The detection technically "works" but not efficiently and the X & Y often needs further tweeking to get it to match up with the image (character) top and left position.

My objective is to have a text file with all the objects collision points for the map that will be read in and processed for each map. (ie: 7000,2000,7500,2100).

Any ideas, or did I confuse everyone with my own confusion?

I thought I also might add, my "character" is just an image obj.

Last edited by vcand; 08-29-2009 at 03:37 AM. Reason: adding more details
Reply With Quote
  #2  
Old 08-29-2009, 10:39 AM
Samapico Samapico is offline
Regular
 
Join Date: Jul 2006
Posts: 58
Default

collision detection does not only depend on position, but on direction as well...

So yeah, you can define a series of 'solid' areas from your text file, then you define the contact area of your character... i.e. if your character is at 300,300, it actually takes from 280,290 to 320,310 , for example.
Then you just attempt to move your character, check the collision box it would give, try to match it up against each solid area you defined, check if they intersect or something.

That would be a pretty easy way to do it I think

Edit: It would also be easier for you to set your picturebox scale to pixels, and simply open the bitmap in paint or whatever and get the coordinates from there

Last edited by Samapico; 08-29-2009 at 11:05 AM.
Reply With Quote
  #3  
Old 08-29-2009, 06:37 PM
AdrianDeAngelis's Avatar
AdrianDeAngelis AdrianDeAngelis is offline
Contributor
 
Join Date: May 2005
Location: Australia
Posts: 549
Default

Let me see if I understand this properly...

You have a background image with all sorts of "stuff" somae which you can walk over and some which you cannot and others which you can interact with. You are trying to create a collision detection map for this image.

OK there are a few ways that you could do this...
1) you could create a second image with colours representing for each location/zone and then use get pixel to check the colour in your collision map and then deal with it appropriately.

OR... and much better

2) Divide the world up into small grid squares similar to a 2D based tile map and set them to either walkable or not etc... When the player moves you find out what square he is on and check the property of the square he is going to move onto. disadvantage is that every square is the same size and may not fit your map without tweaking.

3) Have the world consist of a number of either rectangular or circular zones, you could include both if you wanted for added flexibility. Again the world would be divided into a grid but this time the grid would record only those collision zones that overlap onto the square. When the player moves, you check the grid squares that he is overlapping onto and test if he is colliding with any of the collision zones and react appropriately.

With number 2 & 3 I recommend you write a small map editor that would let you set the collision grid or create the collision zones and then write these to file. It makes life a whole lot easier and is good programming experience. For 3 when you load the list of collision objects you would also create the grid links, not before.

Collision itself is fairly simple:

Circular: ... where X1 and X2 etc... are the x position of the circles centrepoints
Dx = X2 - X1
Dy = Y2 - Y1
D = (Dx * Dx) + (Dy * Dy)
If D <= (R1 + R2) * (R1 + R2) then you have a collision, distance between the center points is less that the sum of the two circle's radii.

Rectangular:
If Bottom1 < Top2 or Top1 > Bottom2 or _
right1 < left2 or left1 > right2 then
'no collision
else
'collision
end if
__________________
Automation error... What do you mean automation error you %#@*&!$ thing!

Star Admiral: 3D tactical space sim *** New Version 0.38 10/01/09 ***
Damage, shields and special weapons systems
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
2D Collision detection.
2D Collision detection.
2D Collision detection. 2D Collision detection.
2D Collision detection.
2D Collision detection.
2D Collision detection. 2D Collision detection. 2D Collision detection. 2D Collision detection. 2D Collision detection. 2D Collision detection. 2D Collision detection.
2D Collision detection.
2D Collision detection.
 
2D Collision detection.
2D Collision detection.
 
-->