3 ms·
Seems to rest on the assumption that an input control provides a vector on the unit circle, and tries to divide that into eight regions, corresponding to unit v
by jameshart 4y ago
Seems to rest on the assumption that an input control provides a vector on the unit circle, and tries to divide that into eight regions, corresponding to unit vectors aligned to compass directions. That seems like an odd assumption though - most analog XY inputs produce a vector with x and y components nominally distributed from -1 to 1, (although in practice constrained by calibration, and not necessarily linear in control stick deflection)
This approach effectively divides the ‘unit square’ of possible input vectors up into a grid, based on cos(pi/8) and cos(3pi/8) gridlines, with basically 9 possible areas in each quadrant mapped to corresponding directional vectors.
It may not be a bad strategy in general to use this kind of grid model, but it needs testing with actual controllers to see what the ‘feel’ ends up being. While this mathematical model makes sense in theory, in practice there’s no reason to suspect that these cosine values are necessarily good thresholds to use to create an intuitive compass direction control that actually feels intuitive.
In general in games, math needs to be a guide, but not a straitjacket for how you approach things.
- dahart 4y agoThis is a good point; some controllers are neither circular nor square. Check out the mapping ranges for a couple of Nintendo’s old controllers: https://electromodder.co.uk/ https://electromodder.co.uk/ That said, Lemire’s approach rewritten as dot products might work nicely and even look a bit more clean, even if it took 3ns instead of 1.5.
- Arrath 4y ago> This is a good point; some controllers are neither circular nor square. Check out the mapping ranges for a couple of Nintendo’s old controllers: https://electromodder.co.uk/ https://electromodder.co.uk/ Very interesting, thanks! I've noticed myself that sometimes if I'm holding the controller a bit skewed my natural impulse will be to push in directions that don't exactly map to what the controller wants. EG I think I'm pushing forward, but I'm moving forward and slightly to the left. And its not just stick drift, its my own user error.
- dahart 4y agoI do the same. Some difficult and brutal platformers will really help you notice how much user error you bring to the table. :P Good point too, because for fast twitchy games where the directions really matter, it’s quite nice to be able to calibrate and/or bias the direction rounding to compensate for my own bias. This could be one good reason to go with the trig code instead - offsetting the angle becomes trivial. It could be done under the covers before the rounding code sees it, but it’d still be doing trig somewhere.
- deleted 4y ago[deleted]