From 841a2bbd6dffa3e55e5832729f1306208d680342 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Tue, 10 Mar 2020 19:12:16 +0100 Subject: [PATCH] clean up old states, lower gravity --- common/src/state.rs | 2 +- common/src/states/fall.rs | 67 -------------------------------------- common/src/states/jump.rs | 27 --------------- common/src/states/stand.rs | 45 ------------------------- common/src/states/swim.rs | 56 ------------------------------- common/src/states/utils.rs | 3 +- common/src/sys/phys.rs | 2 +- 7 files changed, 4 insertions(+), 198 deletions(-) delete mode 100644 common/src/states/fall.rs delete mode 100644 common/src/states/jump.rs delete mode 100644 common/src/states/stand.rs delete mode 100644 common/src/states/swim.rs diff --git a/common/src/state.rs b/common/src/state.rs index 2c5224697a..0e07b75659 100644 --- a/common/src/state.rs +++ b/common/src/state.rs @@ -40,7 +40,7 @@ pub struct DeltaTime(pub f32); /// this value, the game's physics will begin to produce time lag. Ideally, we'd /// avoid such a situation. const MAX_DELTA_TIME: f32 = 1.0; -const HUMANOID_JUMP_ACCEL: f32 = 26.0; +const HUMANOID_JUMP_ACCEL: f32 = 16.0; #[derive(Default)] pub struct BlockChange { diff --git a/common/src/states/fall.rs b/common/src/states/fall.rs deleted file mode 100644 index 8d90711eb2..0000000000 --- a/common/src/states/fall.rs +++ /dev/null @@ -1,67 +0,0 @@ -use crate::comp::{ActionState, CharacterEntityData, MoveState, StateUpdate}; - -use super::utils::*; -use crate::states::StateHandler; -use vek::{Vec2, Vec3}; - -const HUMANOID_AIR_ACCEL: f32 = 10.0; -const HUMANOID_AIR_SPEED: f32 = 100.0; - -#[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct State; - -impl StateHandler for State { - fn new(_ecs_data: &CharacterEntityData) -> Self { Self {} } - - fn handle(&self, ecs_data: &CharacterEntityData) -> StateUpdate { - let mut update = StateUpdate { - pos: *ecs_data.pos, - vel: *ecs_data.vel, - ori: *ecs_data.ori, - character: *ecs_data.character, - }; - - // Move player according to movement direction vector - update.vel.0 += Vec2::broadcast(ecs_data.dt.0) - * ecs_data.inputs.move_dir - * if update.vel.0.magnitude_squared() < HUMANOID_AIR_SPEED.powf(2.0) { - HUMANOID_AIR_ACCEL - } else { - 0.0 - }; - - // Set orientation vector based on direction of movement when on the ground - let ori_dir = - if let ActionState::Attack(_) | ActionState::Block(_) = update.character.action_state { - Vec2::from(ecs_data.inputs.look_dir).normalized() - } else { - Vec2::from(update.vel.0) - }; - - if ori_dir.magnitude_squared() > 0.0001 - && (update.ori.0.normalized() - Vec3::from(ori_dir).normalized()).magnitude_squared() - > 0.001 - { - update.ori.0 = - vek::ops::Slerp::slerp(update.ori.0, ori_dir.into(), 2.0 * ecs_data.dt.0); - } - - // Check to start climbing - if can_climb(ecs_data.physics, ecs_data.inputs, ecs_data.body) { - update.character.move_state = MoveState::Climb(None); - return update; - } - - // Check gliding - if ecs_data.inputs.glide.is_pressed() { - update.character.move_state = MoveState::Glide(None); - return update; - } - - // Else update based on groundedness - update.character.move_state = - determine_move_from_grounded_state(ecs_data.physics, ecs_data.inputs); - - update - } -} diff --git a/common/src/states/jump.rs b/common/src/states/jump.rs deleted file mode 100644 index bb23131736..0000000000 --- a/common/src/states/jump.rs +++ /dev/null @@ -1,27 +0,0 @@ -use super::{CharacterEntityData, MoveState, StateHandler, StateUpdate}; -use crate::event::LocalEvent; - -#[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct State; - -impl StateHandler for State { - fn new(_ecs_data: &CharacterEntityData) -> Self { Self {} } - - fn handle(&self, ecs_data: &CharacterEntityData) -> StateUpdate { - let mut update = StateUpdate { - character: *ecs_data.character, - pos: *ecs_data.pos, - vel: *ecs_data.vel, - ori: *ecs_data.ori, - }; - - ecs_data - .local_bus - .emitter() - .emit(LocalEvent::Jump(*ecs_data.entity)); - - // Immediately go to falling state after jump impulse - update.character.move_state = MoveState::Fall(None); - update - } -} diff --git a/common/src/states/stand.rs b/common/src/states/stand.rs deleted file mode 100644 index c21a024b45..0000000000 --- a/common/src/states/stand.rs +++ /dev/null @@ -1,45 +0,0 @@ -use super::utils::*; -use crate::{ - comp::{CharacterEntityData, MoveState, StateUpdate}, - states::StateHandler, -}; - -#[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] -pub struct State; - -impl StateHandler for State { - fn new(_ecs_data: &CharacterEntityData) -> Self { Self {} } - - fn handle(&self, ecs_data: &CharacterEntityData) -> StateUpdate { - let mut update = StateUpdate { - character: *ecs_data.character, - pos: *ecs_data.pos, - vel: *ecs_data.vel, - ori: *ecs_data.ori, - }; - - // Try to sit - if can_sit(ecs_data.physics, ecs_data.inputs, ecs_data.body) { - update.character.move_state = MoveState::Sit(None); - return update; - } - - // Try to climb - if can_climb(ecs_data.physics, ecs_data.inputs, ecs_data.body) { - update.character.move_state = MoveState::Climb(None); - return update; - } - - // Try to jump - if can_jump(ecs_data.physics, ecs_data.inputs) { - update.character.move_state = MoveState::Jump(None); - return update; - } - - // Else update based on groundedness - update.character.move_state = - determine_move_from_grounded_state(ecs_data.physics, ecs_data.inputs); - - update - } -} diff --git a/common/src/states/swim.rs b/common/src/states/swim.rs deleted file mode 100644 index 0cb327296e..0000000000 --- a/common/src/states/swim.rs +++ /dev/null @@ -1,56 +0,0 @@ -use crate::{ - comp::StateUpdate, - sys::{character_behavior::JoinData, phys::GRAVITY}, -}; -use std::time::Duration; -use vek::{Vec2, Vec3}; - -const HUMANOID_WATER_ACCEL: f32 = 70.0; -const HUMANOID_WATER_SPEED: f32 = 120.0; - -pub fn behavior(data: &JoinData) -> StateUpdate { - let mut update = StateUpdate { - character: *data.character, - pos: *data.pos, - vel: *data.vel, - ori: *data.ori, - energy: *data.energy, - local_events: VecDeque::new(), - server_events: VecDeque::new(), - }; - - // Update velocity - update.vel.0 += Vec2::broadcast(data.dt.0) - * data.inputs.move_dir - * if update.vel.0.magnitude_squared() < HUMANOID_WATER_SPEED.powf(2.0) { - HUMANOID_WATER_ACCEL - } else { - 0.0 - }; - - // Set direction based on move direction when on the ground - let ori_dir = if update.character.is_attack() || update.character.is_block() { - Vec2::from(data.inputs.look_dir).normalized() - } else { - Vec2::from(update.vel.0) - }; - - if ori_dir.magnitude_squared() > 0.0001 - && (update.ori.0.normalized() - Vec3::from(ori_dir).normalized()).magnitude_squared() - > 0.001 - { - update.ori.0 = vek::ops::Slerp::slerp( - update.ori.0, - ori_dir.into(), - if data.physics.on_ground { 9.0 } else { 2.0 } * data.dt.0, - ); - } - - // Force players to pulse jump button to swim up - if data.inputs.jump.is_pressed() && !data.inputs.jump.is_long_press(Duration::from_millis(600)) - { - update.vel.0.z = (update.vel.0.z + data.dt.0 * GRAVITY * 1.25).min(HUMANOID_WATER_SPEED); - } - - update -} diff --git a/common/src/states/utils.rs b/common/src/states/utils.rs index 209593d158..f127863d81 100644 --- a/common/src/states/utils.rs +++ b/common/src/states/utils.rs @@ -20,7 +20,8 @@ const BASE_HUMANOID_WATER_SPEED: f32 = 120.0; // const GLIDE_SPEED: f32 = 45.0; // const BLOCK_ACCEL: f32 = 30.0; // const BLOCK_SPEED: f32 = 75.0; -// // Gravity is 9.81 * 4, so this makes gravity equal to .15 +// Gravity is 9.81 * 4, so this makes gravity equal to .15 //TODO: <- is wrong +// // const GLIDE_ANTIGRAV: f32 = GRAVITY * 0.96; // const CLIMB_SPEED: f32 = 5.0; // const CLIMB_COST: i32 = 5; diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index 8df26f2390..2546af51a9 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -9,7 +9,7 @@ use crate::{ use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage}; use vek::*; -pub const GRAVITY: f32 = 9.81 * 10.0; +pub const GRAVITY: f32 = 9.81 * 5.0; const BOUYANCY: f32 = 0.0; // Friction values used for linear damping. They are unitless quantities. The // value of these quantities must be between zero and one. They represent the