openage
openage copied to clipboard
Entity (character) click-box is too small
It's mainly focussed around their feet. When you click their head or upper body, they aren't selected. Perhaps the clickbox should take into account the height of entities too?
Calculating the exact clickbox is extremely difficult: We'd have to use feedback from the renderer where non-transparent pixels of one units are located at one animation frame step. It's possible, but fucking hard.
The original game just raw-copied the pixels to the frame buffer, so the "ownership" of each pixel can directly be determined. With our 3D-graphics backend we'd have to use queries which must be aware of transparency etc. Adding as a todo to #287.
For now, we could just use the whole sprite as a clickbox, but this will be way too big for many units (e.g. trebuchet).
Why not just calculate a boundary area (excluding invisible pixels of course) when the resource is loaded. Then, when the mouse is clicked, find all those entities that have a boundary box enclosing the mouse click position. Once you've done that, it's just a matter of finding which of those has the lowest depth (e.g: is closest to the bottom of the screen).
Because the collision test can be done efficiently on the GPU. It known what fragment belongs to the pixel. Calculating the clickmask for every animation sprite and testing for collisions would be kinda duplicate to what the GPU is doing anyway.
If you want to be 100% in line with original genie (o. g. from here on out), there's a parameter for each sprite that determines if you should check for a pixel hit or just bounding box: https://github.com/sandsmark/genieutils/blob/master/include/genie/dat/Graphic.h#L82-L91
@sandsmark then we'll use that :)
Our new renderer supports object identification by encoding object ids into colors. From the output texture we can determine the object at that point. Thus, we can indeed implement both variants: the bounding hitbox and the pixel-perfect selection.
This should be exposed in the nyan API for the Selectable ability, too.
Edit: Done.