Very simple click and dragging

main
Elijah Voigt 3 months ago
parent e056503a2e
commit 4854ba5937

@ -679,7 +679,8 @@ fn populate_tree(
commands
.entity(trigger.target())
.insert((mesh, material, transform))
.observe(delete_tree);
.observe(delete_tree)
.observe(drag_tree);
}
fn hide_monologue_preview(
@ -700,3 +701,23 @@ fn hide_monologue_preview(
commands.entity(*preview).despawn_related::<Children>();
}
}
fn drag_tree(
trigger: Trigger<Pointer<Drag>>,
mut query: Query<&mut Transform, With<Tree>>,
camera: Single<(&Camera, &GlobalTransform), With<Camera>>,
window: Single<&Window>
) {
if let Ok(mut t) = query.get_mut(trigger.target()) {
let world_position = window
.cursor_position()
.and_then(|cursor| {
camera.0.viewport_to_world(camera.1, cursor).ok()
}).map(|ray| {
// Compute ray's distance to entity
let distance = ray.intersect_plane(t.translation, InfinitePlane3d::new(t.up())).unwrap();
ray.get_point(distance)
});
t.translation = world_position.unwrap();
}
}

Loading…
Cancel
Save