2D collision detection - sprite to sprite

Blitz3D Forums/Blitz3D Beginners Area/2D collision detection - sprite to sprite

Dax Trajero(Posted 2005) [#1]
There's a lot of experienced people on here, so I thought I'd pick your brains as to the best technique to use for my upcoming sprite collision. Its an all 2D game, using Blitz3D (thats the package I bought)

I need to detect a collision on each side of a sprite so I can write a routine for it to react correctly. eg. if the sprite is hit on the left side, its pushed right, etc...

What I'd like to know is which technique to use. I haven't done this before, so the options I've worked out so far are...

a) I can use a simple 'overlap' detection along with the fact that I know each sprites direction (degrees) and speed so I can calculate a 'reaction'

b) For each sprite frame, I could have a corresponding collision frame which is colour coded on the sides. I could use a Blitz command like ReadPixelFast to work out which colour is in collision and therefore which side.

c) For each sprite frame, I could have FOUR corresponding frames - each representing a side eg. top, bottom, left & right. I could perform a simple 'overlap detection' on the appropriate frame.

Any help would be appreciated


Stevie G(Posted 2005) [#2]
(A) should be fine for what you want to do. You would probably want to know the distance in the x,y axis to the middle of the sprite you're colliding with so that you can push it that same distance. B and C are going a bit overboard I think.


big10p(Posted 2005) [#3]
I agree. (A) sounds like the best option. Is this for proper 2D or 2D-in-3D? This 2D collision detection demo I did may be of some use to you:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1065


Dax Trajero(Posted 2005) [#4]
This is an 'all-2D' game, written using Blitz3D

I'll check out your demo big10p

Thanks for your comments StevieG


Dax Trajero(Posted 2005) [#5]
big10p - nice demo, but I don't think your method is applicable to my game - I have a total of 4 main sprites!

;-)


tonyg(Posted 2005) [#6]
Can't you use ATAN2?


Dax Trajero(Posted 2005) [#7]
ATAN2 ? Haven't come across that yet.


tonyg(Posted 2005) [#8]
Billards styles collisions


Dax Trajero(Posted 2005) [#9]
Ues, I've found some nice code in the archives so will base things around that.


Ross C(Posted 2005) [#10]
The way i did it, is just to calcuate the resulting vector, based on the vectors of the two sprites/images in question.