Using a proxy model and color buffer overlap for hit detections (is this possible?)

Nibbie
Posts: 1
Joined: 2009.04
Post: #1
Hi all!

I have a game where there are enemy targets that move around in 3d space and a player's crosshair (circular) that moves around in 2d space (480 x 320, the screen). Basically the player is just shooting at these enemies.

The enemy models have multiple components (wings, cockpit, etc, spaceshippy). I'd like to compute hit detection based on what parts of the enemy are encompassed by the crosshair when the player performs a 'shoot' action.

I was thinking I could do something like this: render the enemy to some offscreen framebuffer, giving each part of the ship a unique color. Then check to see how many of each color are contained in the crosshair, and assign damage accordingly.

I'm not very comfortable working with multiple buffers, and I've heard that some aspects of iPhone's gl implementation make certain buffer operations impossible. But is this (or some similar idea) possible? Or should I come up with another plan.

Thanks! Any help is hugely appreciated.
Quote this message in a reply
Sage
Posts: 1,234
Joined: 2002.10
Post: #2
This is exactly how Shoot Things does its per-pixel collision detection. It works fine on any desktop Mac, going as far back as G3 iMacs.

However, this is not going to work well on the iPhone; the glReadPixels bandwidth is just too low. You'll be much better off doing a bit of math to project a center point for each enemy to the screen, and then a quick distance check to the crosshairs.
Quote this message in a reply
Post Reply