move some stuff or idk
This commit is contained in:
parent
f101e735f6
commit
d727f52ff0
4 changed files with 39 additions and 38 deletions
33
src/camera.rs
Normal file
33
src/camera.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::player::*;
|
||||
|
||||
pub struct Camera;
|
||||
pub fn camera_follow_player(
|
||||
player: Query<(&Transform, &Player), Without<Camera>>,
|
||||
mut camera: Query<(&mut Transform, &Camera), Without<Player>>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let player_pos = if let Some(player) = player.iter().next() {
|
||||
player.0.translation
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
let ds = time.delta_seconds() * 5.0;
|
||||
for (mut trans, _) in camera.iter_mut() {
|
||||
trans.look_at(player_pos, Vec3::Y);
|
||||
|
||||
// keep a distance to the player
|
||||
if trans.translation.distance(player_pos) > 170.0 {
|
||||
let mut d = trans.rotation * Vec3::Z * ds;
|
||||
d.y = 0.0;
|
||||
trans.translation -= d;
|
||||
}
|
||||
if trans.translation.distance(player_pos) < 130.0 {
|
||||
let mut d = trans.rotation * Vec3::Z * ds;
|
||||
d.y = 0.0;
|
||||
trans.translation += d;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@ mod light_balls;
|
|||
use light_balls::*;
|
||||
mod player;
|
||||
use player::*;
|
||||
mod camera;
|
||||
use camera::*;
|
||||
mod columns;
|
||||
use columns::*;
|
||||
|
||||
|
@ -23,9 +25,6 @@ fn main() {
|
|||
.run();
|
||||
}
|
||||
|
||||
pub struct Camera;
|
||||
|
||||
/// set up a simple 3D scene
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
|
@ -33,7 +32,7 @@ fn setup(
|
|||
mut ambient: ResMut<AmbientLight>,
|
||||
light_ball_materials: Res<LightBallMaterials>,
|
||||
) {
|
||||
// set ambient light to 0
|
||||
// set ambient light to very low
|
||||
ambient.color = Color::rgb(0.3, 0.3, 0.3);
|
||||
ambient.brightness = 0.02;
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::Camera;
|
||||
|
||||
pub struct Player;
|
||||
pub struct PlayerLight {
|
||||
i: u8,
|
||||
|
@ -31,7 +29,7 @@ pub fn spawn_player(
|
|||
light_material.emissive = Color::rgb(15.0, 15.0, 15.0);
|
||||
let light_material = materials.add(light_material);
|
||||
|
||||
for i in 0..10 {
|
||||
for i in 0..6 {
|
||||
parent
|
||||
.spawn_bundle(PbrBundle {
|
||||
mesh: meshes.add(Mesh::from(shape::Icosphere {
|
||||
|
@ -59,7 +57,7 @@ pub fn light_movement(mut query: Query<(&mut Transform, &PlayerLight)>, time: Re
|
|||
for (mut trans, light) in query.iter_mut() {
|
||||
let i = light.i as f64;
|
||||
let i2 = i / 2.0;
|
||||
trans.translation.y = 6.0 * (t * 1.1 * i2 + i).sin() as f32 + 7.0;
|
||||
trans.translation.y = 3.0 * (t * 1.1 * i2 + i).sin() as f32 + 4.0;
|
||||
trans.translation.x = 5.0 * i2 as f32 * (t * 0.4 * i2 + i).cos() as f32;
|
||||
trans.translation.z = 5.0 * (t * 0.4 * i + i).sin() as f32;
|
||||
}
|
||||
|
@ -90,32 +88,3 @@ pub fn move_player(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn camera_follow_player(
|
||||
player: Query<(&Transform, &Player), Without<Camera>>,
|
||||
mut camera: Query<(&mut Transform, &Camera), Without<Player>>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let player_pos = if let Some(player) = player.iter().next() {
|
||||
player.0.translation
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
|
||||
let ds = time.delta_seconds() * 5.0;
|
||||
for (mut trans, _) in camera.iter_mut() {
|
||||
trans.look_at(player_pos, Vec3::Y);
|
||||
|
||||
// keep a distance to the player
|
||||
if trans.translation.distance(player_pos) > 170.0 {
|
||||
let mut d = trans.rotation * Vec3::Z * ds;
|
||||
d.y = 0.0;
|
||||
trans.translation -= d;
|
||||
}
|
||||
if trans.translation.distance(player_pos) < 100.0 {
|
||||
let mut d = trans.rotation * Vec3::Z * ds;
|
||||
d.y = 0.0;
|
||||
trans.translation += d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
#version 450
|
||||
|
||||
const int MAX_LIGHTS = 10;
|
||||
const int MAX_LIGHTS = 30;
|
||||
|
||||
struct Light {
|
||||
mat4 proj;
|
||||
|
|
Loading…
Reference in a new issue