mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
clean up old states, lower gravity
This commit is contained in:
parent
0ce451a8b1
commit
841a2bbd6d
@ -40,7 +40,7 @@ pub struct DeltaTime(pub f32);
|
|||||||
/// this value, the game's physics will begin to produce time lag. Ideally, we'd
|
/// this value, the game's physics will begin to produce time lag. Ideally, we'd
|
||||||
/// avoid such a situation.
|
/// avoid such a situation.
|
||||||
const MAX_DELTA_TIME: f32 = 1.0;
|
const MAX_DELTA_TIME: f32 = 1.0;
|
||||||
const HUMANOID_JUMP_ACCEL: f32 = 26.0;
|
const HUMANOID_JUMP_ACCEL: f32 = 16.0;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct BlockChange {
|
pub struct BlockChange {
|
||||||
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
@ -20,7 +20,8 @@ const BASE_HUMANOID_WATER_SPEED: f32 = 120.0;
|
|||||||
// const GLIDE_SPEED: f32 = 45.0;
|
// const GLIDE_SPEED: f32 = 45.0;
|
||||||
// const BLOCK_ACCEL: f32 = 30.0;
|
// const BLOCK_ACCEL: f32 = 30.0;
|
||||||
// const BLOCK_SPEED: f32 = 75.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 GLIDE_ANTIGRAV: f32 = GRAVITY * 0.96;
|
||||||
// const CLIMB_SPEED: f32 = 5.0;
|
// const CLIMB_SPEED: f32 = 5.0;
|
||||||
// const CLIMB_COST: i32 = 5;
|
// const CLIMB_COST: i32 = 5;
|
||||||
|
@ -9,7 +9,7 @@ use crate::{
|
|||||||
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage};
|
use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
|
|
||||||
pub const GRAVITY: f32 = 9.81 * 10.0;
|
pub const GRAVITY: f32 = 9.81 * 5.0;
|
||||||
const BOUYANCY: f32 = 0.0;
|
const BOUYANCY: f32 = 0.0;
|
||||||
// Friction values used for linear damping. They are unitless quantities. The
|
// Friction values used for linear damping. They are unitless quantities. The
|
||||||
// value of these quantities must be between zero and one. They represent the
|
// value of these quantities must be between zero and one. They represent the
|
||||||
|
Loading…
Reference in New Issue
Block a user