aevyrie / bevy_mod_picking

Picking and pointer events for Bevy.
https://crates.io/crates/bevy_mod_picking
Apache License 2.0
764 stars 170 forks source link

Picking should take the sprite's rect into consideration. #353

Open Sigma-dev opened 1 month ago

Sigma-dev commented 1 month ago

Right now, Sprite picking works just fine, until you start using the sprite's optional rect property.

The rect is used in many cases, one of the most popular being getting individual frames from a spritesheet. This results in the sprite rect and therefore the size of the actual sprite being much smaller than the bounds (that cover the whole sheet). Since bevy_mod_picking only considers the sprite's bounds, then the sprite's actual picking zone is much bigger than it should be, rendering it unusable in many situations.

What I propose is that the bevy_mod_picking instead looks at both the bounds and the rect to determine what area is actually the sprite.

PS: I understand this might not be possible and there might be edge cases or other factors i'm not seeing. There might also be some fix/solution i'm not aware of.

aevyrie commented 1 month ago

This would need to be added to the sprite picking backend, for anyone interested in adding this.

https://github.com/aevyrie/bevy_mod_picking/blob/main/backends/bevy_picking_sprite/src/lib.rs