mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
41 lines
1.2 KiB
Rust
41 lines
1.2 KiB
Rust
|
use super::utils::*;
|
||
|
use crate::{
|
||
|
comp::{character_state::OutputEvents, CharacterState, InventoryAction, StateUpdate},
|
||
|
states::{
|
||
|
behavior::{CharacterBehavior, JoinData},
|
||
|
idle,
|
||
|
},
|
||
|
};
|
||
|
use serde::{Deserialize, Serialize};
|
||
|
use vek::Vec2;
|
||
|
|
||
|
const WALLRUN_ANTIGRAV: f32 = crate::consts::GRAVITY * 0.90;
|
||
|
|
||
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)]
|
||
|
pub struct Data;
|
||
|
|
||
|
impl CharacterBehavior for Data {
|
||
|
fn behavior(&self, data: &JoinData, output_events: &mut OutputEvents) -> StateUpdate {
|
||
|
let mut update = StateUpdate::from(data);
|
||
|
|
||
|
handle_wield(data, &mut update);
|
||
|
handle_jump(data, output_events, &mut update, 1.0);
|
||
|
|
||
|
{
|
||
|
let lift = WALLRUN_ANTIGRAV;
|
||
|
update.vel.0.z += data.dt.0
|
||
|
* lift
|
||
|
* (Vec2::<f32>::from(update.vel.0).magnitude() * 0.075)
|
||
|
.min(1.0)
|
||
|
.max(0.2);
|
||
|
}
|
||
|
|
||
|
// fall off wall or hit ground
|
||
|
if data.physics.on_wall.is_none() || data.physics.on_ground.is_some() {
|
||
|
update.character = CharacterState::Idle(idle::Data { is_sneaking: false });
|
||
|
}
|
||
|
|
||
|
update
|
||
|
}
|
||
|
}
|