Skip to content

Accessing world coordinates via cursor_position #65

@boyswan

Description

@boyswan

I'm struggling to access world coords with a mouse click. My current attempt is along the lines of:

if let Some(pos) = window.cursor_position() {
    if let Ok((camera_transform, camera)) = q_camera.single() {
        let low = camera.get_target_sizes(window).low;
        let size = Vec2::new(low.x as f32, low.y as f32);
   
        let p = pos - size / 2.0;
        let pos_wld = camera_transform.compute_matrix() * p.extend(0.0).extend(1.0);
        let pos = Vec2::new(pos_wld.x, -pos_wld.y);

        info!("world xy", pos);
    }
}

However I can't seem to figure out the correct way to find the coords and am not sure whether bevy_retrograde will require a different calculation (I'm trying to move a sprite to an ldtk tile).

Apologies for making an issue as I know it's not a bug, but I'm not sure where else to ask and have been stuck on this for a while!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions