#How to detect if a sprite is clicked/hovered over (without `bevy-mod-picking`)?
10 messages · Page 1 of 1 (latest)
bevy-mod-picking builds on bevy-mod-raycast which lets you do this without a debug overlay
i made a simple distance checker for this
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
Ah my bad. I wanted to ask about 2D sprites click detection, i.e. detecting clicks on static sprites on a 2D map 🙂
@hearty mantleyes that is what that does
Does it detect the distance to the size of the sprite, or does it check the boundary considering transparent pixels?