#Check if TextBundle is hovered

1 messages · Page 1 of 1 (latest)

sweet perch
#

I got ```rust
pub fn screen_to_world(
window: &Window,
cam_transform: &GlobalTransform,
camera: &Camera,
screen_pos: Vec2,
) -> Vec2 {
let wsize = Vec2::new(window.width(), window.height());
let ndc = (screen_pos / wsize) * 2.0 - Vec2::ONE;
let ndc_to_world = cam_transform.compute_matrix() * camera.projection_matrix().inverse();
ndc_to_world.project_point3(ndc.extend(-1.0)).truncate()
}

To convert mouse to world coords and I'm trying to check if a TextBundles GlobalTransform + CalculatedSize is hovered, however when the text is in upper right corner and I'm hovering it, the positions are way of,

Text global pos: 1538.5, 7.5
Mouse world pos: 712.0, 491.5

Anyone know what's wrong? Or knows a way to check if a Ui element is hovered
spark kestrel
#

The Camera component already have methods to map between screen and world, you could first check if your method is giving the same output as these builtins methods: