More minor cleanup, remove pitch control, embiggen sphere.

This commit is contained in:
Joe Ardent 2022-01-13 17:32:39 -08:00
parent 614e457aa7
commit 768bdf67ad
4 changed files with 38 additions and 48 deletions

View file

@ -57,16 +57,6 @@ fn falling_cat(time: Res<Time>, mut bike_query: Query<&mut Transform, With<Cyber
}
}
fn apply_velocity(time: Res<Time>, mut bike_query: Query<(&mut Transform, &CyberBikeState)>) {
let dt = time.delta_seconds();
let (mut bike_xform, state) = bike_query.single_mut();
if state.velocity.is_finite() {
bike_xform.translation += state.velocity * dt;
}
}
fn update_velocity(
time: Res<Time>,
settings: Res<MovementSettings>,
@ -110,6 +100,34 @@ fn update_velocity(
state.velocity = vel;
}
fn apply_velocity(time: Res<Time>, mut bike_query: Query<(&mut Transform, &CyberBikeState)>) {
let dt = time.delta_seconds();
let (mut bike_xform, state) = bike_query.single_mut();
if state.velocity.is_finite() {
bike_xform.translation += state.velocity * dt;
}
}
fn steer_cyberbike(
settings: Res<MovementSettings>,
windows: Res<Windows>,
time: Res<Time>,
istate: Res<InputState>,
mut query: Query<&mut Transform, With<CyberBike>>,
) {
let window = windows.get_primary().unwrap();
let window_scale = window.height().min(window.width());
let dt = time.delta_seconds();
let mut transform = query.single_mut();
let d_yaw = (settings.sensitivity * dt * window_scale * istate.yaw).to_radians();
let rotation = Quat::from_axis_angle(transform.local_y(), d_yaw);
transform.rotate(rotation);
}
fn collisions(
mut events: EventReader<CollisionEvent>,
mut query: Query<(&Transform, &mut CyberBikeState)>,
@ -142,6 +160,7 @@ impl Plugin for CyberPhysicsPlugin {
.add_system(collisions)
.add_system(falling_cat)
.add_system(update_velocity)
.add_system(steer_cyberbike)
.add_system(apply_velocity);
}
}

View file

@ -1,10 +1,6 @@
use bevy::prelude::*;
use crate::{
action::MovementSettings,
geometry::{CyberBike, SPAWN_ALTITUDE},
input::InputState,
};
use crate::geometry::{CyberBike, SPAWN_ALTITUDE};
pub(crate) const CAM_DIST: f32 = 15.0;
@ -21,7 +17,7 @@ fn setup_cybercam(mut commands: Commands) {
.insert(CyberCam);
}
fn follow_player(
fn follow_cyberbike(
bike_query: Query<&Transform, (Without<CyberCam>, With<CyberBike>)>,
mut cam_query: Query<&mut Transform, (With<CyberCam>, Without<CyberBike>)>,
) {
@ -36,31 +32,10 @@ fn follow_player(
cam_xform.look_at(look_at, up);
}
fn player_look(
settings: Res<MovementSettings>,
windows: Res<Windows>,
time: Res<Time>,
istate: Res<InputState>,
mut query: Query<&mut Transform, With<CyberBike>>,
) {
let window = windows.get_primary().unwrap();
let window_scale = window.height().min(window.width());
let dt = time.delta_seconds();
let mut transform = query.single_mut();
let d_pitch = (settings.sensitivity * dt * window_scale * istate.pitch).to_radians();
let d_yaw = (settings.sensitivity * dt * window_scale * istate.yaw).to_radians();
let rotation = Quat::from_axis_angle(transform.local_y(), d_yaw)
* Quat::from_axis_angle(transform.local_x(), d_pitch);
transform.rotate(rotation);
}
pub struct CyberCamPlugin;
impl Plugin for CyberCamPlugin {
fn build(&self, app: &mut bevy::prelude::App) {
app.add_startup_system(setup_cybercam)
.add_system(follow_player)
.add_system(player_look);
.add_system(follow_cyberbike);
}
}

View file

@ -1,7 +1,7 @@
use bevy::prelude::*;
use heron::prelude::{CollisionShape, RigidBody};
pub const PLANET_RADIUS: f32 = 150.0;
pub const PLANET_RADIUS: f32 = 350.0;
pub(crate) const SPAWN_ALTITUDE: f32 = PLANET_RADIUS + 100.0;
#[derive(Component, Debug)]
@ -19,7 +19,7 @@ fn spawn_giant_sphere(
.spawn_bundle(PbrBundle {
mesh: meshes.add(Mesh::from(shape::Icosphere {
radius: PLANET_RADIUS,
subdivisions: 6,
subdivisions: 8,
})),
material: materials.add(StandardMaterial {
base_color: Color::GRAY,

View file

@ -1,18 +1,15 @@
use bevy::{
app::{Events, ManualEventReader},
prelude::{
info, App, GamepadAxisType, GamepadButtonType, GamepadEvent, GamepadEventType, Plugin, Res,
ResMut,
},
prelude::*,
};
#[derive(Default)]
pub(crate) struct InputState {
event_reader: ManualEventReader<GamepadEvent>,
pub pitch: f32,
pub yaw: f32,
pub throttle: f32,
pub brake: bool,
pub _pitch: f32,
}
fn update_input(events: Res<Events<GamepadEvent>>, mut istate: ResMut<InputState>) {
@ -34,9 +31,8 @@ fn update_input(events: Res<Events<GamepadEvent>>, mut istate: ResMut<InputState
GamepadEventType::AxisChanged(GamepadAxisType::LeftStickX, val) => {
istate.yaw = -val;
}
GamepadEventType::AxisChanged(GamepadAxisType::LeftStickY, val) => {
istate.pitch = -val;
}
// ignore spurious vertical movement for now
GamepadEventType::AxisChanged(GamepadAxisType::LeftStickY, _) => {}
_ => {
info!("unhandled gamepad event: {:?}", ev);
}