Just a quick idea off the top of my head. What if you just get a rect covering from the bullets previous position to the bullets new position?
Quick psuedo-code: xpos = min(old.left, new.left) xpos2 = max(old.right, new.right) width = pos2 - pos #Do the same for y/height Rect(xpos, ypos, width, height) Then do collision detection with that. To be absolutely sure, you could do the same trick for the enemy rect first. Just a rough idea, hope that helps. On Mon, 2012-02-20 at 13:50 -0800, Julian Marchant wrote: > Hi, I tried searching the internet for an answer, but didn't find anything, > so I'll ask here. > > One problem with normal collision detection I'm sure we're all aware of is > the problem that objects moving too fast can pass through other objects > without a collision happening. I'm experiencing this problem with a scrolling > shooter I'm working on because both bullets and enemies move pretty fast, one > enemy is very small, and the frame rate is usually somewhat low (maybe 30 > FPS) on the machine I'm targeting. > > Now, obviously, I intend to make other changes which will help, e.g. making > these tiny enemies bigger, but I'd like to tackle the problem directly. There > are two ways I can think of: The first way, which I easily could implement > and would be most effective, is to move the bullets in steps and do collision > detection each step. I have done something like this in a previous game and > it worked well, but it seems like overkill in this game (the bullet subrect > is only 5x5 pixels) and it isn't perfect anyway. > > The second way, which I would prefer, is to detect collision with a line from > the bullet's new position to the bullet's previous position. I've seen this > discussed on the Game Maker Community. The problem with this is I have no > idea of how this could be done in a remotely efficient manner. The only > method I can think of is to check every individual pixel one at a time, which > is obviously not a good idea. Bullets can move diagonally, so just checking > the x or y position won't work. > > So, in a nutshell, my question is: how could I do "line collision" detection > like this in a relatively efficient way?
signature.asc
Description: This is a digitally signed message part