gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Fixed point collision detection

#9306 - VgSlag - Fri Aug 01, 2003 10:14 am

I'm making asteroids on the GBA as a way for me to learn... I have all the movement working using a fixed point trig lookup table, the asteroid is moving nicely too.

I'm using this fixed point code here: http://members.aol.com/form1/fixed.htm

I'm storing all values as fixed point to keep the speed up then convert it to float when placing the sprites x and y.

My asteroid is a 64 x 64 graphic which when x > 240(as a fixed number) appers at -64(as a fixed number).

For the collision I'm getting the distance between the fixed x of the bullet and fixed x of the asteroid + fixed asteroind radius (distX) and storing it as a fixed also. I'm doing the same with y then working out if it's collided by checking dist = Mulfx(distX, distX) + Mulfx(distY, distY) against the fixed radius of the asteroid squared...

That works fine, it's really nice, my problem is when the asteroid is very near the left or right of the screen, if you're firing left and the asteroid is moving off the right of the screen my shot dissapear asthough hitting an invisible asteroid, the same happens the opposite way round too :(

Once the asteroid has changed fully to the other side it all goes back to normal. Does anyone know why? Is it to do with my numbers getting too high?

ANy help would be greatly, greatly appreciated.

Thanks,

G

#9415 - Wanderer - Mon Aug 04, 2003 11:36 am

Hi,

it isn't that your numbers are getting too high. The problem is that if the asteroid is going off the right of the screen it's X=239, for the bullet on the left side of the screen X=-64 say... to your calculations the are over 300 pixels apart.

Personally I'd try to avoid having negative positions, I would make the coordinates range from 0-303 then if the value is >239 correct it in the part of your code that displays the sprites.

To deal with the collisions when your sprites are in this difficult area, I'd probably compare their positions and use this to decide which direction the two are closest in, and use that as the X distance.

You'll need to do the same for the Y coords too,


Wanderer.

#9417 - funkeejeffou - Mon Aug 04, 2003 1:03 pm

Maybe what I'm going to say is stupid, but what about "killing" your bullets when ((x<0) or (x>239)) or ((y<0) or ((y>159)). In that way, whatever happens when an asteroids goes off the screen, your bullets won't interact anymore.
By the way, what kind of fixed point format are you using, and on wich type of variable (16, 32 bits)?