In 2d, when I have 2 Meshes that are exactly adjacent to each other, I can position the mouse right on the edge between them, and the click won't be captured. Is this how it is supposed to work? User error?
For example, creating a chessboard like this (every square is exactly 50 wide, and 50 away from each other, you can put the mouse right between the squares and the click won't be recognized.
use bevy::{
prelude::*,
sprite::{MaterialMesh2dBundle, Mesh2dHandle},
window::WindowResolution,
};
use bevy_mod_picking::prelude::*;
#[derive(Component)]
struct MainCamera;
fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(400., 400.).with_scale_factor_override(1.0),
resizable: false,
..default()
}),
..default()
}))
.add_plugins(DefaultPickingPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<ColorMaterial>>,
) {
commands.spawn((
Camera2dBundle {
transform: Transform {
translation: Vec3 {
x: 200.,
y: 200.,
z: 0.,
},
..default()
},
..default()
},
MainCamera,
));
let mut color = Color::BEIGE;
for x in 0..8_usize {
for y in 0..8_usize {
commands.spawn((
PickableBundle::default(),
On::<Pointer<Click>>::run(move || {
info!("({x}, {y})");
}),
MaterialMesh2dBundle {
mesh: Mesh2dHandle(meshes.add(Rectangle::new(50.0, 50.0))),
transform: Transform::from_translation(Vec3 {
x: ((x * 50) + 25) as f32,
y: ((y * 50) + 25) as f32,
z: 0.,
}),
material: materials.add(color),
..default()
},
));
match color {
Color::BEIGE => color = Color::DARK_GREEN,
Color::DARK_GREEN => color = Color::BEIGE,
_ => panic!("wtf is going on"),
}
}
match color {
Color::BEIGE => color = Color::DARK_GREEN,
Color::DARK_GREEN => color = Color::BEIGE,
_ => panic!("wtf is going on"),
}
}
}
[dependencies]
bevy = { version = "0.13.2" }
bevy_mod_picking = { version = "0.19.0", features = [
"backend_raycast",
], default-features = false }
In 2d, when I have 2 Meshes that are exactly adjacent to each other, I can position the mouse right on the edge between them, and the click won't be captured. Is this how it is supposed to work? User error?
For example, creating a chessboard like this (every square is exactly
50wide, and50away from each other, you can put the mouse right between the squares and the click won't be recognized.