Put the camera behind the bike.

This commit is contained in:
Joe Ardent 2022-01-07 00:45:05 -08:00
parent f53cd2f848
commit 7ab0730dfd
2 changed files with 19 additions and 9 deletions

View File

@ -12,7 +12,7 @@ use heron::{
CollisionEvent, CollisionEvent,
}; };
pub const PLANET_RADIUS: f32 = 75.0; pub const PLANET_RADIUS: f32 = 150.0;
const PLAYER_DIST: f32 = PLANET_RADIUS + 100.0; const PLAYER_DIST: f32 = PLANET_RADIUS + 100.0;
const CAM_DIST: f32 = 50.0; const CAM_DIST: f32 = 50.0;
@ -91,7 +91,7 @@ fn setup_player(mut commands: Commands, asset_server: Res<AssetServer>) {
.insert(PlayerState::default()); .insert(PlayerState::default());
} }
fn setup_dbg_ui(mut commands: Commands, asset_server: Res<AssetServer>) { fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn_bundle(UiCameraBundle::default()); commands.spawn_bundle(UiCameraBundle::default());
commands commands
@ -160,9 +160,12 @@ fn player_move(
bike_xform.translation += player_state.velocity * dt; bike_xform.translation += player_state.velocity * dt;
} }
let look_at = bike_xform.translation;
let cam_pos = bike_xform.translation + (bike_xform.back() * CAM_DIST * 1.3) + (up * CAM_DIST);
let (mut cam_xform, _) = cam_query.single_mut(); let (mut cam_xform, _) = cam_query.single_mut();
cam_xform.translation = bike_xform.translation + (up * CAM_DIST); cam_xform.translation = cam_pos;
cam_xform.look_at(bike_xform.translation, Vec3::Y); cam_xform.look_at(look_at, up);
} }
fn player_look( fn player_look(
@ -282,7 +285,7 @@ impl Plugin for PlayerPlugin {
.init_resource::<MovementSettings>() .init_resource::<MovementSettings>()
.init_resource::<InputState>() .init_resource::<InputState>()
.add_startup_system(setup_player) .add_startup_system(setup_player)
.add_startup_system(setup_dbg_ui) .add_startup_system(setup_ui)
.add_system(ui_system) .add_system(ui_system)
.add_system(player_move.label("move")) .add_system(player_move.label("move"))
.add_system(player_look.after("move")) .add_system(player_look.after("move"))

View File

@ -14,7 +14,7 @@ fn main() {
.insert_resource(MovementSettings { .insert_resource(MovementSettings {
sensitivity: 0.3, // default: 1.0 sensitivity: 0.3, // default: 1.0
accel: 20.0, // default: 40.0 accel: 20.0, // default: 40.0
drag: 0.1, // default: 0.05 drag: 0.01, // default: 0.0005
gravity: 10.0, // default: 10.0 gravity: 10.0, // default: 10.0
}) })
.add_startup_system(setup.label("world")) .add_startup_system(setup.label("world"))
@ -42,6 +42,7 @@ fn setup(
intensity: 1_000.0, intensity: 1_000.0,
range: LIGHT_RANGE, range: LIGHT_RANGE,
color: Color::RED, color: Color::RED,
radius: 10.0,
..Default::default() ..Default::default()
}; };
@ -49,6 +50,7 @@ fn setup(
intensity: 1_000.0, intensity: 1_000.0,
range: LIGHT_RANGE, range: LIGHT_RANGE,
color: Color::BLUE, color: Color::BLUE,
radius: 10.0,
..Default::default() ..Default::default()
}; };
@ -56,12 +58,13 @@ fn setup(
intensity: 1_000.0, intensity: 1_000.0,
range: LIGHT_RANGE, range: LIGHT_RANGE,
color: Color::PURPLE, color: Color::PURPLE,
radius: 10.0,
..Default::default() ..Default::default()
}; };
commands.insert_resource(AmbientLight { commands.insert_resource(AmbientLight {
color: Color::WHITE, color: Color::WHITE,
brightness: 0.12, brightness: 0.32,
}); });
// world // world
@ -218,7 +221,11 @@ fn setup(
}); });
} }
fn animate_lights(mut query: Query<&mut Transform, (With<PointLight>, With<Animate>)>) { fn animate_lights(
time: Res<Time>,
mut query: Query<&mut Transform, (With<PointLight>, With<Animate>)>,
) {
let dt = time.delta_seconds();
for mut transform in query.iter_mut() { for mut transform in query.iter_mut() {
let translation = &transform.translation; let translation = &transform.translation;
let x = translation.x; let x = translation.x;
@ -230,7 +237,7 @@ fn animate_lights(mut query: Query<&mut Transform, (With<PointLight>, With<Anima
}; };
// 10 degrees == 0.174533 radians // 10 degrees == 0.174533 radians
let anim_rate = 0.174533 / 5.0; let anim_rate = 0.174533 * dt;
let theta = z.atan2(x) + anim_rate; let theta = z.atan2(x) + anim_rate;
let x_new = LIGHT_DIST * theta.cos(); let x_new = LIGHT_DIST * theta.cos();
let z_new = LIGHT_DIST * theta.sin(); let z_new = LIGHT_DIST * theta.sin();