openage icon indicating copy to clipboard operation
openage copied to clipboard

Entity (character) click-box is too small

Open zesterer opened this issue 10 years ago • 6 comments

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?

zesterer avatar Aug 25 '15 18:08 zesterer

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).

TheJJ avatar Aug 25 '15 18:08 TheJJ

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).

zesterer avatar Aug 25 '15 19:08 zesterer

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.

TheJJ avatar Aug 25 '15 19:08 TheJJ

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 avatar Dec 06 '19 02:12 sandsmark

@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.

TheJJ avatar Dec 06 '19 12:12 TheJJ

This should be exposed in the nyan API for the Selectable ability, too.

Edit: Done.

heinezen avatar Dec 06 '19 12:12 heinezen