bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
34.37k stars 3.36k forks source link

Smart method to get Entity when hovering it with mouse for 2d #3805

Open pyweeker opened 2 years ago

pyweeker commented 2 years ago

Hello, is it possible to have something equivalent than bevy_mod_picking https://github.com/aevyrie/bevy_mod_picking
which works for 3d , but here for 2d ? i tried to get inspiration from buttons , but it is not clean to put this kind of component everywhere. I dont know how to writte this kind of method. I'd like to hover sprites , click on it to select it , or click and drag to draw a rectangle which select a vector or entities. So i need to get entity / entities when the mouse hovers sprite(s). very usefull++

SUPERCILEX commented 2 years ago

I've done this with rapier colliders: https://docs.rs/bevy_rapier2d/latest/bevy_rapier2d/prelude/struct.QueryPipeline.html#method.intersections_with_point

SUPERCILEX commented 2 years ago

I also filed https://github.com/aevyrie/bevy_mod_picking/issues/130 to get Lyon support.

aevyrie commented 2 years ago

This has been added to bevy_mod_raycast: https://github.com/aevyrie/bevy_mod_raycast/pull/38 Currently downstreaming into bevy_mod_picking.

xavierwoo commented 1 month ago

I just created a very simple plugin for this.

https://github.com/xavierwoo/bevy_cursor_hovering_sprite

Hope it meet your need.