Skip to content

Commit

Permalink
DemoBevy: remove smooth-bevy-cameras
Browse files Browse the repository at this point in the history
Replace with simple camera_follow system
  • Loading branch information
lucaspoffo committed Dec 1, 2024
1 parent 420c8a5 commit 457633d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 32 deletions.
1 change: 0 additions & 1 deletion demo_bevy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ serde = { version = "1.0", features = ["derive"] }
bincode = "1.3"
bevy_egui = "0.31.1"
renet_visualizer = { path = "../renet_visualizer", features = ["bevy"] }
smooth-bevy-cameras = "0.12"
fastrand = "2.0"
steamworks = { version = "0.11", optional = true }
46 changes: 21 additions & 25 deletions demo_bevy/src/bin/client.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
use std::collections::HashMap;

use bevy::window::PrimaryWindow;
use bevy::{
diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin},
prelude::Vec3,
prelude::*,
prelude::Vec3
};
use bevy::window::PrimaryWindow;
use bevy_egui::{EguiContexts, EguiPlugin};
use bevy_renet::{client_connected, renet::{ClientId, RenetClient}, RenetClientPlugin};
use bevy_renet::{
client_connected,
renet::{ClientId, RenetClient},
RenetClientPlugin,
};
use demo_bevy::{
connection_config, setup_level, ClientChannel, NetworkedEntities, PlayerCommand, PlayerInput, ServerChannel, ServerMessages,
};
use renet_visualizer::{RenetClientVisualizer, RenetVisualizerStyle};
// use smooth_bevy_cameras::{LookTransform, LookTransformBundle, LookTransformPlugin, Smoother};

#[derive(Component)]
struct ControlledPlayer;
Expand Down Expand Up @@ -122,7 +125,6 @@ fn main() {
let mut app = App::new();
app.add_plugins(DefaultPlugins);
app.add_plugins(RenetClientPlugin);
// app.add_plugins(LookTransformPlugin);
app.add_plugins(FrameTimeDiagnosticsPlugin);
app.add_plugins(LogDiagnosticsPlugin::default());
app.add_plugins(EguiPlugin);
Expand All @@ -139,7 +141,7 @@ fn main() {
app.insert_resource(PlayerInput::default());
app.insert_resource(NetworkMapping::default());

app.add_systems(Update, (player_input, /*camera_follow,*/ update_target_system));
app.add_systems(Update, (player_input, camera_follow, update_target_system));
app.add_systems(
Update,
(client_send_input, client_send_player_commands, client_sync_players).in_set(Connected),
Expand Down Expand Up @@ -297,19 +299,10 @@ fn update_target_system(
}

fn setup_camera(mut commands: Commands) {
commands
.spawn(/*LookTransformBundle {
transform: LookTransform {
eye: Vec3::new(0.0, 8., 2.5),
target: Vec3::new(0.0, 0.5, 0.0),
up: Vec3::Y,
},
smoother: Smoother::new(0.9),
})
.insert(*/(
Camera3d::default(),
Transform::from_xyz(0., 8.0, 2.5).looking_at(Vec3::new(0.0, 0.5, 0.0), Vec3::Y),
));
commands.spawn((
Camera3d::default(),
Transform::from_xyz(0., 8.0, 2.5).looking_at(Vec3::new(0.0, 0.5, 0.0), Vec3::Y),
));
}

fn setup_target(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, mut materials: ResMut<Assets<StandardMaterial>>) {
Expand All @@ -322,15 +315,18 @@ fn setup_target(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>, mut ma
.insert(Target);
}

/*fn camera_follow(
mut camera_query: Query<&mut LookTransform, (With<Camera>, Without<ControlledPlayer>)>,
fn camera_follow(
time: Res<Time>,
mut camera_query: Query<&mut Transform, (With<Camera>, Without<ControlledPlayer>)>,
player_query: Query<&Transform, With<ControlledPlayer>>,
) {
let mut cam_transform = camera_query.single_mut();
if let Ok(player_transform) = player_query.get_single() {
cam_transform.eye.x = player_transform.translation.x;
cam_transform.eye.z = player_transform.translation.z + 2.5;
cam_transform.target = player_transform.translation;
let eye = Vec3::new(player_transform.translation.x, 8., player_transform.translation.z + 2.5);
if eye.distance(cam_transform.translation) > 10.0 {
cam_transform.translation = eye;
} else {
cam_transform.translation.smooth_nudge(&eye, 8.0, time.delta_secs());
}
}
}
*/
2 changes: 1 addition & 1 deletion renet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ version = "0.0.16"
bevy = ["dep:bevy_ecs"]

[dependencies]
bevy_ecs = { version = "0.15.0", optional = true }
bevy_ecs = { version = "0.15", optional = true }
bytes = "1.1"
log = "0.4.17"
octets = "0.3"
Expand Down
3 changes: 1 addition & 2 deletions renet/src/remote_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use octets::OctetsMut;
use std::collections::{BTreeMap, HashMap};
use std::ops::Range;
use std::time::Duration;
use bevy_ecs::system::Resource;

/// Configuration for a renet connection and its channels.
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -80,7 +79,7 @@ pub enum RenetConnectionStatus {
}

#[derive(Debug)]
#[cfg_attr(feature = "bevy", derive(Resource))]
#[cfg_attr(feature = "bevy", derive(bevy_ecs::system::Resource))]
pub struct RenetClient {
packet_sequence: u64,
current_time: Duration,
Expand Down
2 changes: 1 addition & 1 deletion renet_netcode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bevy = ["dep:bevy_ecs"]
[dependencies]
renet = { version = "0.0.16", path = "../renet" }
renetcode = { path = "../renetcode", version = "0.0.12" }
bevy_ecs = { version = "0.15.0", optional = true }
bevy_ecs = { version = "0.15", optional = true }
log = "0.4.19"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion renet_steam/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bevy = ["dep:bevy_ecs"]
renet = { version = "0.0.16", path = "../renet" }
steamworks = "0.11"
log = "0.4.19"
bevy_ecs = { version = "0.15.0", optional = true }
bevy_ecs = { version = "0.15", optional = true }

[dev-dependencies]
env_logger = "0.11"
2 changes: 1 addition & 1 deletion renet_visualizer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ bevy = ["dep:bevy_ecs"]
[dependencies]
renet = { path = "../renet", version = "0.0.16" }
egui = "0.29.1"
bevy_ecs = { version = "0.15.0", optional = true }
bevy_ecs = { version = "0.15", optional = true }

0 comments on commit 457633d

Please sign in to comment.