Skip to content

Commit 37ed698

Browse files
author
Carter Hollman
committed
fix: resolved issues found in PR
1 parent fed7272 commit 37ed698

File tree

2 files changed

+11
-39
lines changed

2 files changed

+11
-39
lines changed

game/src/camera/camera_plugin.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use bevy::{input::mouse::MouseWheel, prelude::*};
2+
use avian2d::prelude::*;
23

34
pub struct CameraPlugin;
45

@@ -13,7 +14,9 @@ pub struct MainCamera;
1314
impl Plugin for CameraPlugin {
1415
fn build(&self, app: &mut App) {
1516
app.add_systems(Startup, setup_main_camera);
16-
app.add_systems(Update, (update_camera, zoom_camera).chain());
17+
app.add_systems(PostUpdate, update_camera.after(PhysicsSet::Sync)
18+
.before(TransformSystem::TransformPropagate));
19+
app.add_systems(Update, zoom_camera);
1720
}
1821
}
1922

@@ -27,27 +30,23 @@ fn update_camera(
2730
mut camera_query: Query<&mut Transform, (With<MainCamera>, Without<CameraTarget>)>,
2831
target_query: Query<&Transform, (With<CameraTarget>, Without<MainCamera>)>,
2932
) {
30-
//getting camera from query
33+
3134
let Ok(mut camera) = camera_query.get_single_mut() else {
35+
error!("could not execute query for single MainCamera component");
3236
return;
3337
};
3438

35-
//getting target from query
3639
let Ok(target) = target_query.get_single() else {
40+
error!("Could not execute query for single CameraTarget component");
3741
return;
3842
};
3943

40-
//Gets the x and y coordinates of our target
44+
4145
let Vec3 { x, y, .. } = target.translation;
4246

43-
//Stores the target x y with our camera z cuz our camera z not changing
47+
4448
let direction = Vec3::new(x, y, camera.translation.z);
4549

46-
//Debug statements if we want to use them :)
47-
//info!("Camera: {:?}", camera);
48-
//info!("Target: {:?}", target);
49-
50-
//Make our camera translation match our target translation
5150
camera.translation = direction;
5251
}
5352

@@ -62,14 +61,13 @@ fn zoom_camera(
6261
//Amount to zoom in this update cycle
6362
let mut zoom_amount = 0.0;
6463

65-
//For every event read in this cycle increase the zoom amount by 1 event * sensitivity
64+
6665
for event in scroll_event.read() {
6766
zoom_amount += -event.y * zoom_factor
6867
}
6968

70-
//If we have had any mouse scroll events in this update then apply it to the camera projection
69+
7170
if zoom_amount != 0.0 {
72-
//extracting the type of projection from camera, only ever going to be Orthographic since 2d but I don't know a better way lol
7371
for mut projection in camera.iter_mut() {
7472
projection.scale += zoom_amount;
7573

game/src/debug/debug_plugin.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
use avian2d::math::*;
2-
use avian2d::prelude::*;
31
use bevy::prelude::*;
42

5-
use crate::camera::camera_plugin::*;
6-
use crate::movement::plugin::*;
7-
83
///This plugin provides terminal debug capabilities
94
///By adding systems, requested information will be printed to the terminal
105
pub struct DebugPlugin;
@@ -13,7 +8,6 @@ pub struct DebugPlugin;
138
impl Plugin for DebugPlugin {
149
fn build(&self, app: &mut App) {
1510
app.add_systems(Startup, print_debug_active_message);
16-
app.add_systems(Startup, display_dudes);
1711
}
1812
}
1913

@@ -23,24 +17,4 @@ fn print_debug_active_message() {
2317
info!("The debugger is active!");
2418
}
2519

26-
//Displays two pixel like sprites where one is stationary, then the other that has the CameraTarget component
27-
//falls forever. Used to test camera system tracking and zooming.
28-
fn display_dudes(mut commands: Commands) {
29-
commands
30-
.spawn((
31-
SpriteBundle::default(),
32-
CharacterControllerBundle::new(Collider::capsule(12.5, 20.0)).with_movement(
33-
1250.0,
34-
0.92,
35-
400.0,
36-
(30.0 as Scalar).to_radians(),
37-
),
38-
Friction::ZERO.with_combine_rule(CoefficientCombine::Min),
39-
Restitution::ZERO.with_combine_rule(CoefficientCombine::Min),
40-
ColliderDensity(2.0),
41-
GravityScale(1.5),
42-
))
43-
.insert(CameraTarget);
4420

45-
commands.spawn(SpriteBundle::default());
46-
}

0 commit comments

Comments
 (0)