I'm trying out mouse inputs, so far I am moving my spawners on mouse click 1 tile to the right with this code:
fn move_sources(
mut spawners: Query<(&mut TilePosition, &MoveOnClick)>,
mut mouse_input: Res<Input<MouseButton>>,
) {
for (mut spawner, move_on) in &mut spawners {
if mouse_input.just_pressed(move_on.mouse_button) {
spawner.x = (spawner.x + 1) % 10; // TODO: hardwired level width
}
}
}
This is working well, but now I want to move the spawner to the position where the mouse click happened. Is there a way to get the click coordinates from the mouse input event? I have a simple 2D game with a tile grid.
I tried looking at this example: https://bevy-cheatbook.github.io/cookbook/cursor2world.html but it looks so damn complicated. I guess there can be multiple worlds, so getting the world coordinates needs you to specify which world's coordinates you want?
Is there a more simple way to get the world coordinates of the click when it happens?