Solved

VB5: Collision Detection

Posted on 2000-05-08
9
285 Views
Last Modified: 2010-05-02
I'm running into problems with my collision detection in a game I'm working on.  Basically I need some good example source showing how to do collision detection between 2 complex objects by the pixel.  No generic boxes or circles...by the pixel using images.  Simple example, 2 guys swinging swords at each other.  You need collision detection down to the pixel to know when the swords hit each other, when they hit the guy, and when they miss.
So advanced input and some source code would be helpfull.
0
Comment
Question by:ChrisK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 2788254
Maybe you need to create a table in advanced based on the X-Y displacement of one figure relative to another.  e.g. (10,5) might be a hit (10,6) a miss.  Values outside the range of the table would be a miss.  

It could also hold info about what picture to display to depict the hit, e.g hit on head or body.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2788438
Here's a thought.  Create regions which are the outlines of your pictures, then you can determine if they intersect by calling the CombineRgn API call:

If NULLREGION = CombineRgn(hrgnDst, hRgn1, hRgn2, RGN_AND) Then
    'They do not intersect
End If

This site shows how to create regions from bitmaps:

"Creating Window Shapes from Bitmaps"
http://vbaccelerator.com/codelib/winstyle/bmpwinsh.htm
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2788758
example here towards the bottom of the page:

http://www.coderoom.com/pages/graphics/graphics17.htm


same site, dont know if its a different sample or not:

http://www.coderoom.com/pages/graphics/graphics2.htm
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Accepted Solution

by:
Ruchi earned 161 total points
ID: 2789337
"If you want to write any games that require collision detection, this excellent sample shows you how to do pixel collision detection in VB5 or greater."
http://www.zarr.net/vb/download/download.asp?id=47

"This example demonstrates how to performs accurate pixel collision detection. "
http://www.extreme-vb.net/upload/Collision.zip
0
 
LVL 2

Author Comment

by:ChrisK
ID: 2790457
All of these are excellent examples.  But there's still 1 problem with them all.  Ruchi's for example shows pixel collision but requires masks of both objects to do it.  I may be able to structure the game code to make this work...but here's the catch.  Take my sword fighting example.  How could I tell the difference between the pixels of the swords colliding, and the pixels of the sword hitting the guy?  If the sword was a seperate object from the guy, it wouldn't be too tough, but they are all the same image...any suggestions?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2790466
is there a distinct color difference such that you can use the rgb value of the pixel to distinguish between the two?
0
 
LVL 2

Author Comment

by:ChrisK
ID: 2790490
Nope...that wouldn't work because there will be a large variety of weapons and such which would have the same color values.  I think I solved my own problem really...I just need to make the weapons a seperate object that gets drawn either before or after the character, depending on the angle.  Then I could map the characters body coordinates to 1 variable, and the coordinates of the weapon image to another.
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2790971
Go to
http://www.planetsourcecode.com/vb
Type collision detection in the text box for searching.
You should be able to get 8 entries. Hope they are helpful to you.
0
 
LVL 2

Author Comment

by:ChrisK
ID: 2794939
Several of you had good examples, but ruchi's seems to be the best for what I need.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question