veloren/common/src/states/wallrun.rs

45 lines
1.3 KiB
Rust
Raw Normal View History

2022-02-03 09:01:23 +00:00
use super::utils::*;
use crate::{
2022-02-05 04:59:57 +00:00
comp::{character_state::OutputEvents, CharacterState, StateUpdate},
2022-02-03 09:01:23 +00:00
states::{
behavior::{CharacterBehavior, JoinData},
idle,
},
};
use serde::{Deserialize, Serialize};
use vek::Vec2;
2022-02-05 04:59:57 +00:00
const WALLRUN_ANTIGRAV: f32 = crate::consts::GRAVITY * 0.5;
2022-02-03 09:01:23 +00:00
#[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);
2022-02-05 04:59:57 +00:00
handle_climb(data, &mut update);
2022-02-03 09:01:23 +00:00
{
let lift = WALLRUN_ANTIGRAV;
update.vel.0.z += data.dt.0
* lift
2023-03-11 12:59:30 +00:00
* (Vec2::<f32>::from(update.vel.0).magnitude() * 0.075).clamp(0.2, 1.0);
2022-02-03 09:01:23 +00:00
}
// fall off wall, hit ground, or enter water
// TODO: Rugged way to determine when state change occurs and we need to leave
// this state
if data.physics.on_wall.is_none()
|| data.physics.on_ground.is_some()
2022-05-26 09:08:41 +00:00
|| data.physics.in_liquid().is_some()
{
2022-05-27 17:19:52 +00:00
update.character = CharacterState::Idle(idle::Data::default());
2022-02-03 09:01:23 +00:00
}
update
}
}