Compare commits

..

No commits in common. "b34f1a94b180d65e6c7b40c496919ae6b75b1a73" and "93e34b2c88fd3dbc7f6d8509d7a04d33c48ce512" have entirely different histories.

4 changed files with 311 additions and 336 deletions

View file

@ -3,31 +3,10 @@ use shipyard::{Component, View, ViewMut, IntoIter, UniqueView, Workload, IntoWor
use std::f32::consts::PI;
use crate::{transform::Transform, input::Inputs, settings::GameSettings, delta_time::DeltaTime};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum PlayerControllerType {
FlyCam,
FpsCtl,
}
#[derive(Component)]
pub struct PlayerController {
pub control_type: PlayerControllerType,
pub speed: f32,
}
pub struct FlyController;
impl PlayerController {
pub const DEFAULT_FLY_CAM: Self = Self {
control_type: PlayerControllerType::FlyCam,
speed: 30.,
};
pub const DEFAULT_FPS_CTL: Self = Self {
control_type: PlayerControllerType::FpsCtl,
speed: 10.,
};
}
pub fn update_player_controllers() -> Workload {
pub fn update_controllers() -> Workload {
(
update_look,
update_movement
@ -37,7 +16,7 @@ pub fn update_player_controllers() -> Workload {
const MAX_PITCH: f32 = PI/2. - 0.05;
fn update_look(
controllers: View<PlayerController>,
controllers: View<FlyController>,
mut transforms: ViewMut<Transform, track::All>,
inputs: UniqueView<Inputs>,
settings: UniqueView<GameSettings>,
@ -57,18 +36,18 @@ fn update_look(
}
fn update_movement(
controllers: View<PlayerController>,
controllers: View<FlyController>,
mut transforms: ViewMut<Transform, track::All>,
inputs: UniqueView<Inputs>,
dt: UniqueView<DeltaTime>,
) {
if inputs.movement == Vec2::ZERO { return }
let movement = inputs.movement * dt.0.as_secs_f32();
for (ctl, mut transform) in (&controllers, &mut transforms).iter() {
let movement = inputs.movement * 30. * dt.0.as_secs_f32();
for (_, mut transform) in (&controllers, &mut transforms).iter() {
let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation();
let rotation_norm = rotation.normalize();
translation += (rotation_norm * Vec3::NEG_Z).normalize() * movement.y * ctl.speed;
translation += (rotation_norm * Vec3::X).normalize() * movement.x * ctl.speed;
translation += (rotation_norm * Vec3::NEG_Z).normalize() * movement.y;
translation += (rotation_norm * Vec3::X).normalize() * movement.x;
transform.0 = Mat4::from_scale_rotation_translation(scale, rotation_norm, translation);
}
}

View file

@ -19,7 +19,6 @@ pub struct Inputs {
pub look: Vec2,
pub action_a: bool,
pub action_b: bool,
pub jump: bool,
}
#[derive(Unique, Clone, Copy, Default, Debug)]
@ -187,7 +186,6 @@ fn update_input_state (
inputs.look += raw_inputs.mouse_delta.as_vec2();
inputs.action_a |= raw_inputs.button_state[0];
inputs.action_b |= raw_inputs.button_state[1];
inputs.jump |= raw_inputs.button_state[2];
}
fn update_input_state_gamepad (
@ -200,11 +198,9 @@ fn update_input_state_gamepad (
let left_stick = vec2(gamepad.value(Axis::LeftStickX), gamepad.value(Axis::LeftStickY));
let right_stick = vec2(gamepad.value(Axis::RightStickX), -gamepad.value(Axis::RightStickY));
inputs.movement += left_stick;
//HACK: for now, we multiply look by 2 to make it feel more responsive
inputs.look += right_stick * 2.;
inputs.action_a |= gamepad.is_pressed(Button::West);
inputs.look += right_stick;
inputs.action_a |= gamepad.is_pressed(Button::South);
inputs.action_b |= gamepad.is_pressed(Button::East);
inputs.jump |= gamepad.is_pressed(Button::South);
}
}
}

View file

@ -23,7 +23,7 @@ pub(crate) mod settings;
pub(crate) mod camera;
pub(crate) mod events;
pub(crate) mod input;
pub(crate) mod player_controller;
pub(crate) mod fly_controller;
pub(crate) mod block_placement;
pub(crate) mod delta_time;
pub(crate) mod cursor_lock;
@ -57,7 +57,7 @@ use events::{
player_actions::generate_move_events,
};
use input::{init_input, process_inputs};
use player_controller::update_player_controllers;
use fly_controller::update_controllers;
use rendering::{
Renderer,
RenderTarget,
@ -133,7 +133,7 @@ fn update() -> Workload {
update_loaded_world_around_player,
).into_sequential_workload().run_if(is_ingame_or_loading),
(
update_player_controllers,
update_controllers,
update_client_physics_late,
generate_move_events,
update_raycasts,

View file

@ -12,7 +12,7 @@ use kubi_shared::{
use crate::{
camera::Camera,
client_physics::ClPhysicsActor,
player_controller::PlayerController,
fly_controller::FlyController,
transform::Transform,
world::raycast::LookingAtBlock
};
@ -31,7 +31,7 @@ pub fn spawn_player (
Health::new(PLAYER_HEALTH),
Transform::default(),
Camera::default(),
PlayerController::DEFAULT_FPS_CTL,
FlyController,
LookingAtBlock::default(),
PlayerHolding(Some(Block::Cobblestone)),
Username("LocalPlayer".into()),
@ -53,7 +53,7 @@ pub fn spawn_local_player_multiplayer (
init.health,
Transform(Mat4::from_rotation_translation(init.direction, init.position)),
Camera::default(),
PlayerController::DEFAULT_FPS_CTL,
FlyController,
LookingAtBlock::default(),
PlayerHolding::default(),
),(