Unit picking #2

There was a factual mistake in the previous Unit Picking article. Thanks to Lewin for pointing at it. Original KaM did NOT used pixel-perfect unit picking, but what did it used instead?

KaM unit picking seems to work by just checking unit sprite bounds. If cursor is within bounds (even on units shadow or empty corner) the unit gets picked. House picking is tile-based. Clicking on any tile that the house is standing on will pick the house.

I see two reasons behind this behavior. First one is that this is faster from performance point of view, checking just the bounds is quicker than accessing pixel data. Secondly that is more user friendly: player can click anywhere near the unit and still get it picked, without feeling frustrated about 1 pixel miss. There are advantages to the houses grid-picking as well, that way they don’t occlude units standing behind them.

All of that means that color-picking approach described in previous article is not the best fit for the game. In-game tests confirmed that despite being more precise method, aiming at unit became harder because of the shape instability (swinging arms and legs) and overall hitable area reduced in size.

However we still can fix it with just a few modification to the transparency handling. We remove alpha testing and render whole sprites area instead:

unitpicking_5

You may ask, why don’t we just do the bounds hit-test while rendering and spare the whole selection buffer idea instead? Because we still need to handle fog of war (FOW) occlusion. Units on the edge of FOW should be pickable only by their visible parts. Doing that sort of test combined with bounds testing programmatically would be much more complicated and prone to errors if we change FOW handling in future.

unitpicking_6

Finding the right balance between precision and usability is hard. You need to try a few ideas before picking a good one 🙂

This entry was posted in Development. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

*