PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Best method you have found for collision detection with eVB

I am trying to find a collision detection routine that is fast enough to be of use with eVB,

What would be best? or what do you use?

Boundary Checking Method, psuedo code below.

if my bullet x is >=enemyx and <=enemyx+enemywidth then
if my bullet y is >=enemyy and <=enemyy+enemyheight then
collision!
end if
end if


That is the only method currently I know, I have heard of Point Checking Method , Rounding To Block Boundary Method and Screen Masks

What type of collision detection have you guys used in the past for optimum performance?

I am thinking of using it in a shooter

- jarin
TechMage will know for sure on this one.
I am also toying with the idea of using Pythagoras therom, as I think the above hit detection would do strange things at wierd angles,

DIST=((XS-XP)^2+(YS-YP)^2)^0.5
IF DIST<15 THEN
collision!
ELSE { move again }

DIST=distance from object using pythagoras theorem
XS,YS=shot coords, XP,YP=Enemy coords.
15 = size of object

Since that uses the radius of the object I reckon that would be angle independant.

Would that use to much clock cycles?

- Jarin
Yes, square-rooting is fairly clock-intensive. If your game runs fast already, though, there's nothing to worry about.
The square root is not necessary. Just square what you're testing against as well.

DIST=((XS-XP)^2+(YS-YP)^2)
IF DIST<225 THEN
collision!
ELSE { move again }

If the object you are testing against is square or rectangular (or close to it), then your first technique would be more accurate if your bounding box is in alignment with the shape of image. Otherwise using a bounding circle may work better, which is what your latter technique uses.

Dan East
Thanks guys for your great responses!

Dan, good advice on that square root, never thought of that DOH! :)

Thanks again guys that was great advice.

Just toying with evb atm, to get the fram work of the game going then move to evc for the real deal :twisted:

- Jarin
Yeah I'm using the AspriteCE control for my shooter game so collisions are a breeze with both other sprites and the screen edges.

Here's an example:

Code:
Const SPRITE1 = 1
Const SPRITE2 = 2

ASpriteControll.SpriteDefine SPRITE1, App.Path & "\Sprite1.gif", 0, 0, 30, 30, 0, 0
'imagewidth,imageheight,framecount,colums

ASpriteControll.SpriteDefine SPRITE2, App.Path & "\Sprite2.gif", 0, 0, 50, 35, 0, 0

Private Sub ASpriteControl1_SpriteCollision(ByVal lSpriteNum1 As Long, ByVal lSpriteNum2 As Long, ByVal x As Integer, ByVal y As Integer)
'collisions with other sprites
If (lSpriteNum1 = SPRITE1 And lSpriteNum2 = SPRITE2) Then
'insert what happens here
End If



Pretty simple huh?
Well speak of the devil. ASpriteCE is now freeware. You can get it at http://www.spritehand.com

I payed 30 bucks for this control just a few months ago. If you're making eVB games, this is a must have.