#How to detect if a sprite is clicked/hovered over (without `bevy-mod-picking`)?

10 messages · Page 1 of 1 (latest)

hearty mantle
#

Just curious if there's a simple way to detect if a sprite is clicked/interacted with since bevy-mod-picking has mouse debugging on. Cheers!

muted reef
#

bevy-mod-picking builds on bevy-mod-raycast which lets you do this without a debug overlay

grizzled pasture
#
for event in mouse_button_input_events.iter() {
            info!("{:?}", event);
            for mut player_transform in &mut player_query {
                for location in cursor_moved_events.iter() {
                    info!("{:?}", location);
                    let translateMouse = Vec3::new(location.position.x/4.0f32-100.0f32, location.position.y/4.0f32-75.0f32, 1.0f32);
                    if(closeEnough(translateMouse, player_transform.translation)){
                    player_transform.translation = translateMouse;
                    }
                }
            }
#
fn closeEnough(
        mouse: Vec3,
        entity: Vec3,
    ) -> bool {
        return Vec3::distance(mouse, entity)<30.0;
              //  entity.translation = Vec3::new(location.position.x/4.0f32-100.0f32, location.position.y/4.0f32-75.0f32, 1.0f32);

    }
#

could probably get away with fast distance (removes the square root part of distance trig algorithm)

#

rstar may be a better approach for multiple entities

hearty mantle
#

Ah my bad. I wanted to ask about 2D sprites click detection, i.e. detecting clicks on static sprites on a 2D map 🙂

grizzled pasture
#

@hearty mantleyes that is what that does

analog laurel