@@ -5,15 +5,17 @@ use std::time::{SystemTime, UNIX_EPOCH};
55use std:: { fs:: File , io:: Write , sync:: mpsc:: channel} ;
66
77use bevy_app:: { App , Plugin , Update } ;
8+ use bevy_camera:: Camera ;
89use bevy_ecs:: prelude:: * ;
910#[ cfg( feature = "screenrecording" ) ]
1011use bevy_image:: Image ;
1112use bevy_input:: { common_conditions:: input_just_pressed, keyboard:: KeyCode } ;
13+ use bevy_math:: { Quat , StableInterpolate , Vec3 } ;
1214#[ cfg( feature = "screenrecording" ) ]
1315use bevy_render:: view:: screenshot:: ScreenshotCaptured ;
1416use bevy_render:: view:: screenshot:: { save_to_disk, Screenshot } ;
15- #[ cfg( feature = "screenrecording" ) ]
1617use bevy_time:: Time ;
18+ use bevy_transform:: components:: Transform ;
1719use bevy_window:: { PrimaryWindow , Window } ;
1820#[ cfg( feature = "screenrecording" ) ]
1921use tracing:: info;
@@ -257,3 +259,46 @@ impl Plugin for EasyScreenRecordPlugin {
257259 ) ;
258260 }
259261}
262+
263+ /// Plugin to move the camera smoothly according to the current time
264+ pub struct EasyCameraMovementPlugin {
265+ /// Decay rate for the camera movement
266+ pub decay_rate : f32 ,
267+ }
268+
269+ impl Default for EasyCameraMovementPlugin {
270+ fn default ( ) -> Self {
271+ Self { decay_rate : 1.0 }
272+ }
273+ }
274+
275+ /// Move the camera to the given position
276+ #[ derive( Component ) ]
277+ pub struct CameraMovement {
278+ /// Target position for the camera movement
279+ pub translation : Vec3 ,
280+ /// Target rotation for the camera movement
281+ pub rotation : Quat ,
282+ }
283+
284+ impl Plugin for EasyCameraMovementPlugin {
285+ fn build ( & self , app : & mut App ) {
286+ let decay_rate = self . decay_rate ;
287+ app. add_systems (
288+ Update ,
289+ move |mut query : Single < ( & mut Transform , & CameraMovement ) , With < Camera > > ,
290+ time : Res < Time > | {
291+ let target = query. 1 ;
292+ query. 0 . translation . smooth_nudge (
293+ & target. translation ,
294+ decay_rate,
295+ time. delta_secs ( ) ,
296+ ) ;
297+ query
298+ . 0
299+ . rotation
300+ . smooth_nudge ( & target. rotation , decay_rate, time. delta_secs ( ) ) ;
301+ } ,
302+ ) ;
303+ }
304+ }
0 commit comments