[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Line collision detection?
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Line collision detection?
- From: Julian Marchant <onpon4@xxxxxxxxx>
- Date: Mon, 20 Feb 2012 13:50:19 -0800 (PST)
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Mon, 20 Feb 2012 16:50:25 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1329774619; bh=W2GOuf7vKewGJiYwZLMv+i/obJXA9v35tleINNMzmbA=; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=UEeqMK/IGCb+FFqU1jEcMFskWAXxXKFgxvzuYc/5r7TyeUgb1Om/xTM1onKFCPWS4/G2yqjDD76geriaLCWIbu4G1QOGhd+nkCspn8tiQtV/fuAi1gTmlU7QjrYJRSDKGjZ/Sm04oDyFo3LAB2uLSwLgZruhHRDpKrWFBmIU9mM=
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=QqcR6r+2j4cxaxyOy4Bmg0TW8AyrIlfzA0i9rxF20B2wwji+c6FoU7/ix03ydZaq7by7gLMaM/unCQ8ocGKghz02nE1LSCapcYTq7zGbDCCgIOS5xyK0uw2M3Fzxy2R9uaavGFHWab/vjfW2i/yV8cbe6G+tKqRn9fTIonS8yyg=;
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
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?