File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ impl Plugin for PegAnimation {
1717 fn build ( & self , app : & mut App ) {
1818 app. add_systems ( Update , snap_to_board_grid) ;
1919 app. add_systems ( Update , follow_mouse) ;
20+ app. add_systems ( Update , follow_touch) ;
2021 }
2122}
2223
@@ -59,3 +60,23 @@ fn follow_mouse(
5960 }
6061 }
6162}
63+
64+ fn follow_touch (
65+ camera_query : Single < ( & Camera , & GlobalTransform ) > ,
66+ mut transforms : Query < & mut Transform , With < Selected > > ,
67+ touches : Res < Touches > ,
68+ ) {
69+ let ( camera, camera_transform) = * camera_query;
70+ for touch in touches. iter ( ) {
71+ if let Some ( mut destination) = viewport_to_world ( touch. position ( ) , camera, camera_transform)
72+ {
73+ for mut transform in & mut transforms {
74+ let current_z = transform. translation . z ;
75+ let destination_z = PEG_POS_RAISED ;
76+ destination. z = current_z. lerp ( destination_z, 0.2 ) ;
77+ transform. translation = destination;
78+ // no need to RequestRedraw, since mouse movement already triggers a wakeup
79+ }
80+ }
81+ }
82+ }
You can’t perform that action at this time.
0 commit comments