pub fn mouse_camera_pan(
mut camera_query: Query<
(
&ActionState<CameraAction>,
&mut Transform,
&OrthographicProjection,
),
With<MainCamera>,
>,
) {
let Some((action_state, mut transform, projection)) = camera_query.get_single_mut().ok() else {
return;
};
if !action_state.pressed(&CameraAction::MousePan) {
return;
}
// leafwing_input_manager
let Some(movement_delta) = action_state.axis_pair(&CameraAction::MousePan) else {
return;
};
let movement_delta = Vec2::new(-movement_delta.x(), movement_delta.y());
let new_pos = transform.translation.xy() + movement_delta * projection.scale * 0.75;
transform.translation = new_pos.extend(transform.translation.z);
}
This code is what I am currently using to move my camera in my 2d top down game. new_pos is annoyingly being muiltiplied by a magic number, and the number isn't even correct. Without it your camera appears to slide around in the world. What I want is for the cursor to stay in the same position in world space, which I figured could be done just by taking the movement_delta given to me from leafwing_input_manager and multiplying it by the zoom level (projection.scale), but this oddly doesn't work.