use bevy::prelude::*; use bevy::sprite::MaterialMesh2dBundle; use spring_motion::{SpringDescription, SpringSystem}; #[derive(Component)] struct SpringState { position: SpringSystem, } impl Default for SpringState { fn default() -> Self { Self { position: SpringSystem::new( SpringDescription { frequency: 3., damping: 0.5, initial_response: 0., }, Vec2::splat(0.), Vec2::splat(0.), ), } } } #[derive(Component, Default)] struct Target(Vec2); fn track_mouse( mut query: Query<&mut Target>, mut mouse: EventReader, camera_query: Query<(&Camera, &GlobalTransform)>, ) { let (camera, camera_transform) = camera_query.single(); let mut target = query.single_mut(); for event in mouse.iter() { if let Some(mouse_position) = camera .viewport_to_world(camera_transform, event.position) .map(|r| r.origin.truncate()) { target.0 = mouse_position; } } } fn animate_spring(mut query: Query<(&mut SpringState, &mut Transform, &Target)>, time: Res