wallrunning

This commit is contained in:
jshipsey 2022-02-03 04:01:23 -05:00
parent 6f8cadc847
commit 6d34a6b544
9 changed files with 315 additions and 1 deletions

View File

@ -121,6 +121,8 @@ pub enum CharacterState {
/// Handles logic for interacting with a sprite, e.g. using a chest or /// Handles logic for interacting with a sprite, e.g. using a chest or
/// picking a plant /// picking a plant
SpriteInteract(sprite_interact::Data), SpriteInteract(sprite_interact::Data),
/// Runs on the wall
Wallrun(wallrun::Data),
} }
impl CharacterState { impl CharacterState {
@ -294,6 +296,7 @@ impl CharacterState {
CharacterState::Idle(data) => data.behavior(j, output_events), CharacterState::Idle(data) => data.behavior(j, output_events),
CharacterState::Talk => states::talk::Data.behavior(j, output_events), CharacterState::Talk => states::talk::Data.behavior(j, output_events),
CharacterState::Climb(data) => data.behavior(j, output_events), CharacterState::Climb(data) => data.behavior(j, output_events),
CharacterState::Wallrun(data) => data.behavior(j, output_events),
CharacterState::Glide(data) => data.behavior(j, output_events), CharacterState::Glide(data) => data.behavior(j, output_events),
CharacterState::GlideWield(data) => data.behavior(j, output_events), CharacterState::GlideWield(data) => data.behavior(j, output_events),
CharacterState::Stunned(data) => data.behavior(j, output_events), CharacterState::Stunned(data) => data.behavior(j, output_events),
@ -339,6 +342,7 @@ impl CharacterState {
CharacterState::Idle(data) => data.handle_event(j, output_events, action), CharacterState::Idle(data) => data.handle_event(j, output_events, action),
CharacterState::Talk => states::talk::Data.handle_event(j, output_events, action), CharacterState::Talk => states::talk::Data.handle_event(j, output_events, action),
CharacterState::Climb(data) => data.handle_event(j, output_events, action), CharacterState::Climb(data) => data.handle_event(j, output_events, action),
CharacterState::Wallrun(data) => data.handle_event(j, output_events, action),
CharacterState::Glide(data) => data.handle_event(j, output_events, action), CharacterState::Glide(data) => data.handle_event(j, output_events, action),
CharacterState::GlideWield(data) => data.handle_event(j, output_events, action), CharacterState::GlideWield(data) => data.handle_event(j, output_events, action),
CharacterState::Stunned(data) => data.handle_event(j, output_events, action), CharacterState::Stunned(data) => data.handle_event(j, output_events, action),

View File

@ -19,6 +19,7 @@ impl CharacterBehavior for Data {
handle_jump(data, output_events, &mut update, 1.0); handle_jump(data, output_events, &mut update, 1.0);
handle_wield(data, &mut update); handle_wield(data, &mut update);
handle_climb(data, &mut update); handle_climb(data, &mut update);
handle_wallrun(data, &mut update);
handle_dodge_input(data, &mut update); handle_dodge_input(data, &mut update);
// Try to Fall/Stand up/Move // Try to Fall/Stand up/Move

View File

@ -30,4 +30,5 @@ pub mod stunned;
pub mod talk; pub mod talk;
pub mod use_item; pub mod use_item;
pub mod utils; pub mod utils;
pub mod wallrun;
pub mod wielding; pub mod wielding;

View File

@ -657,6 +657,22 @@ pub fn handle_climb(data: &JoinData<'_>, update: &mut StateUpdate) -> bool {
} }
} }
pub fn handle_wallrun(data: &JoinData<'_>, update: &mut StateUpdate) -> bool {
if data.physics.on_wall.is_some()
&& data.physics.on_ground.is_none()
&& !data
.physics
.in_liquid()
.map(|depth| depth > 1.0)
.unwrap_or(false)
&& data.body.can_climb()
{
update.character = CharacterState::Wallrun(wallrun::Data);
true
} else {
false
}
}
/// Checks that player can Swap Weapons and updates `Loadout` if so /// Checks that player can Swap Weapons and updates `Loadout` if so
pub fn attempt_swap_equipped_weapons(data: &JoinData<'_>, update: &mut StateUpdate) { pub fn attempt_swap_equipped_weapons(data: &JoinData<'_>, update: &mut StateUpdate) {
if data if data

View File

@ -0,0 +1,40 @@
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
}
}

View File

@ -197,6 +197,7 @@ impl<'a> System<'a> for Sys {
}, },
// Abilities that temporarily stall energy gain, but preserve regen_rate. // Abilities that temporarily stall energy gain, but preserve regen_rate.
CharacterState::Roll { .. } CharacterState::Roll { .. }
| CharacterState::Wallrun { .. }
| CharacterState::Climb { .. } | CharacterState::Climb { .. }
| CharacterState::Stunned { .. } | CharacterState::Stunned { .. }
| CharacterState::BasicBlock { .. } | CharacterState::BasicBlock { .. }

View File

@ -32,6 +32,7 @@ pub mod stunned;
pub mod swim; pub mod swim;
pub mod swimwield; pub mod swimwield;
pub mod talk; pub mod talk;
pub mod wallrun;
pub mod wield; pub mod wield;
// Reexports // Reexports
@ -46,7 +47,7 @@ pub use self::{
sneakequip::SneakEquipAnimation, sneakwield::SneakWieldAnimation, spin::SpinAnimation, sneakequip::SneakEquipAnimation, sneakwield::SneakWieldAnimation, spin::SpinAnimation,
spinmelee::SpinMeleeAnimation, staggered::StaggeredAnimation, stand::StandAnimation, spinmelee::SpinMeleeAnimation, staggered::StaggeredAnimation, stand::StandAnimation,
stunned::StunnedAnimation, swim::SwimAnimation, swimwield::SwimWieldAnimation, stunned::StunnedAnimation, swim::SwimAnimation, swimwield::SwimWieldAnimation,
talk::TalkAnimation, wield::WieldAnimation, talk::TalkAnimation, wallrun::WallrunAnimation, wield::WieldAnimation,
}; };
use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton}; use super::{make_bone, vek::*, FigureBoneData, Offsets, Skeleton};
use common::comp; use common::comp;

View File

@ -0,0 +1,230 @@
use super::{
super::{vek::*, Animation},
CharacterSkeleton, SkeletonAttr,
};
use common::comp::item::{Hands, ToolKind};
use core::{f32::consts::PI, ops::Mul};
pub struct WallrunAnimation;
type WallrunAnimationDependency = (
Option<ToolKind>,
Option<ToolKind>,
(Option<Hands>, Option<Hands>),
Vec3<f32>,
Vec3<f32>,
Vec3<f32>,
f32,
Vec3<f32>,
f32,
Option<Vec3<f32>>,
);
impl Animation for WallrunAnimation {
type Dependency<'a> = WallrunAnimationDependency;
type Skeleton = CharacterSkeleton;
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"character_wallrun\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "character_wallrun")]
fn update_skeleton_inner<'a>(
skeleton: &Self::Skeleton,
(
active_tool_kind,
second_tool_kind,
hands,
velocity,
orientation,
last_ori,
global_time,
avg_vel,
acc_vel,
wall,
): Self::Dependency<'a>,
anim_time: f32,
rate: &mut f32,
s_a: &SkeletonAttr,
) -> Self::Skeleton {
let mut next = (*skeleton).clone();
let speed = Vec2::<f32>::from(velocity).magnitude();
*rate = 1.0;
let speednorm = (speed / 9.4).powf(0.6);
let lab: f32 = 0.8;
let footrotl = ((1.0 / (0.5 + (0.5) * ((acc_vel * 1.6 * lab + PI * 1.4).sin()).powi(2)))
.sqrt())
* ((acc_vel * 1.6 * lab + PI * 1.4).sin());
let footrotr = ((1.0 / (0.5 + (0.5) * ((acc_vel * 1.6 * lab + PI * 0.4).sin()).powi(2)))
.sqrt())
* ((acc_vel * 1.6 * lab + PI * 0.4).sin());
let shorte = ((1.0 / (0.8 + 0.2 * ((acc_vel * lab * 1.6).sin()).powi(2))).sqrt())
* ((acc_vel * lab * 1.6).sin());
let foothoril = (acc_vel * 2.2 * lab + PI * 1.45).sin();
let foothorir = (acc_vel * 2.2 * lab + PI * (0.45)).sin();
let footvertl = (acc_vel * 1.6 * lab).sin();
let footvertr = (acc_vel * 1.6 * lab + PI).sin();
let footvertsl = (acc_vel * 1.6 * lab).sin();
let footvertsr = (acc_vel * 1.6 * lab + PI * 0.5).sin();
let shortalt = (acc_vel * lab * 2.2 + PI / 1.0).sin();
let short = ((5.0 / (1.5 + 3.5 * ((acc_vel * lab * 1.6).sin()).powi(2))).sqrt())
* ((acc_vel * lab * 1.6).sin());
next.shorts.position = Vec3::new(0.0, s_a.shorts.0 + 2.0, s_a.shorts.1 + 1.0);
next.belt.position = Vec3::new(0.0, s_a.belt.0 + 1.0, s_a.belt.1);
next.foot_l.position = Vec3::new(
-s_a.foot.0,
s_a.foot.1 + foothorir * 6.0,
s_a.foot.2 + shortalt * 2.0 + 2.0,
);
next.foot_l.orientation = Quaternion::rotation_x(0.6 + shortalt * 0.8);
next.foot_r.position = Vec3::new(
s_a.foot.0,
s_a.foot.1 + foothoril * 6.0,
s_a.foot.2 + shortalt * -2.0 + 2.0,
);
next.foot_r.orientation = Quaternion::rotation_x(0.6 - shortalt * 0.8);
next.belt.orientation = Quaternion::rotation_x(0.3);
next.shorts.orientation = Quaternion::rotation_x(0.5);
next.head.position = Vec3::new(0.0, s_a.head.0, s_a.head.1);
next.chest.position = Vec3::new(0.0, s_a.chest.0, s_a.chest.1 + shortalt * 0.0);
//
next.shoulder_l.position = Vec3::new(-s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
next.shoulder_l.orientation = Quaternion::rotation_x(short * 0.15);
next.shoulder_r.position = Vec3::new(s_a.shoulder.0, s_a.shoulder.1, s_a.shoulder.2);
next.shoulder_r.orientation = Quaternion::rotation_x(short * -0.15);
if wall.map_or(false, |e| e.y > 0.5) {
let push = (1.0 - orientation.x.abs()).powi(2);
let right_sub = -(orientation.x).min(0.0);
let left_sub = (orientation.x).max(0.0);
next.hand_l.position = Vec3::new(
-s_a.hand.0,
s_a.hand.1,
s_a.hand.2 + push * 5.0 + 2.0 * left_sub,
);
next.hand_r.position = Vec3::new(
s_a.hand.0,
s_a.hand.1,
s_a.hand.2 + push * 5.0 + 2.0 * right_sub,
);
next.hand_l.orientation =
Quaternion::rotation_x(push * 2.0 + footrotr * -0.2 * right_sub)
* Quaternion::rotation_y(1.0 * left_sub)
* Quaternion::rotation_z(2.5 * left_sub + 1.0 * right_sub);
next.hand_r.orientation =
Quaternion::rotation_x(push * 2.0 + footrotl * -0.2 * left_sub)
* Quaternion::rotation_y(-1.0 * right_sub)
* Quaternion::rotation_z(-2.5 * right_sub - 1.0 * left_sub);
next.torso.orientation = Quaternion::rotation_y(orientation.x / 1.5);
next.chest.orientation = Quaternion::rotation_y(orientation.x / -3.0)
* Quaternion::rotation_z(shortalt * -0.2);
next.head.orientation = Quaternion::rotation_z(shortalt * 0.25)
* Quaternion::rotation_z(orientation.x / -2.0)
* Quaternion::rotation_x(-0.1);
} else if wall.map_or(false, |e| e.y < -0.5) {
let push = (1.0 - orientation.x.abs()).powi(2);
let right_sub = (orientation.x).max(0.0);
let left_sub = -(orientation.x).min(0.0);
next.hand_l.position = Vec3::new(
-s_a.hand.0,
s_a.hand.1,
s_a.hand.2 + push * 5.0 + 2.0 * left_sub,
);
next.hand_r.position = Vec3::new(
s_a.hand.0,
s_a.hand.1,
s_a.hand.2 + push * 5.0 + 2.0 * right_sub,
);
next.hand_l.orientation =
Quaternion::rotation_x(push * 2.0 + footrotr * -0.2 * right_sub)
* Quaternion::rotation_y(1.0 * left_sub)
* Quaternion::rotation_z(2.5 * left_sub + 1.0 * right_sub);
next.hand_r.orientation =
Quaternion::rotation_x(push * 2.0 + footrotl * -0.2 * left_sub)
* Quaternion::rotation_y(-1.0 * right_sub)
* Quaternion::rotation_z(-2.5 * right_sub - 1.0 * left_sub);
next.chest.orientation = Quaternion::rotation_y(orientation.x);
next.torso.orientation = Quaternion::rotation_y(orientation.x / -1.5);
next.chest.orientation = Quaternion::rotation_y(orientation.x / 3.0)
* Quaternion::rotation_z(shortalt * -0.2);
next.head.orientation = Quaternion::rotation_z(shortalt * 0.25)
* Quaternion::rotation_z(orientation.x / 2.0)
* Quaternion::rotation_x(-0.1);
} else if wall.map_or(false, |e| e.x < -0.5) {
let push = (1.0 - orientation.y.abs()).powi(2);
let right_sub = -(orientation.y).min(0.0);
let left_sub = (orientation.y).max(0.0);
next.hand_l.position = Vec3::new(
-s_a.hand.0,
s_a.hand.1,
s_a.hand.2 + push * 5.0 + 2.0 * left_sub,
);
next.hand_r.position = Vec3::new(
s_a.hand.0,
s_a.hand.1,
s_a.hand.2 + push * 5.0 + 2.0 * right_sub,
);
next.hand_l.orientation =
Quaternion::rotation_x(push * 2.0 + footrotr * -0.2 * right_sub)
* Quaternion::rotation_y(1.0 * left_sub)
* Quaternion::rotation_z(2.5 * left_sub + 1.0 * right_sub);
next.hand_r.orientation =
Quaternion::rotation_x(push * 2.0 + footrotl * -0.2 * left_sub)
* Quaternion::rotation_y(-1.0 * right_sub)
* Quaternion::rotation_z(-2.5 * right_sub - 1.0 * left_sub);
next.torso.orientation = Quaternion::rotation_y(orientation.y / 1.5);
next.chest.orientation = Quaternion::rotation_y(orientation.y / -3.0)
* Quaternion::rotation_z(shortalt * -0.2);
next.head.orientation = Quaternion::rotation_z(shortalt * 0.25)
* Quaternion::rotation_z(orientation.y / -2.0)
* Quaternion::rotation_x(-0.1);
} else if wall.map_or(false, |e| e.x > 0.5) {
let push = (1.0 - orientation.y.abs()).powi(2);
let right_sub = (orientation.y).max(0.0);
let left_sub = -(orientation.y).min(0.0);
next.hand_l.position = Vec3::new(
-s_a.hand.0,
s_a.hand.1,
s_a.hand.2 + push * 5.0 + 2.0 * left_sub,
);
next.hand_r.position = Vec3::new(
s_a.hand.0,
s_a.hand.1,
s_a.hand.2 + push * 5.0 + 2.0 * right_sub,
);
next.hand_l.orientation =
Quaternion::rotation_x(push * 2.0 + footrotr * -0.2 * right_sub)
* Quaternion::rotation_y(1.0 * left_sub)
* Quaternion::rotation_z(2.5 * left_sub + 1.0 * right_sub);
next.hand_r.orientation =
Quaternion::rotation_x(push * 2.0 + footrotl * -0.2 * left_sub)
* Quaternion::rotation_y(-1.0 * right_sub)
* Quaternion::rotation_z(-2.5 * right_sub - 1.0 * left_sub);
next.torso.orientation = Quaternion::rotation_y(orientation.y / -1.5);
next.chest.orientation = Quaternion::rotation_y(orientation.y / 3.0)
* Quaternion::rotation_z(shortalt * -0.2);
next.head.orientation = Quaternion::rotation_z(shortalt * 0.25)
* Quaternion::rotation_z(orientation.y / 2.0)
* Quaternion::rotation_x(-0.1);
};
next
}
}

View File

@ -1712,6 +1712,26 @@ impl FigureMgr {
skeleton_attr, skeleton_attr,
) )
}, },
CharacterState::Wallrun(data) => {
anim::character::WallrunAnimation::update_skeleton(
&target_base,
(
active_tool_kind,
second_tool_kind,
hands,
rel_vel,
ori * anim::vek::Vec3::<f32>::unit_y(),
state.last_ori * anim::vek::Vec3::<f32>::unit_y(),
time,
rel_avg_vel,
state.acc_vel,
wall_dir,
),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
)
},
CharacterState::Dance { .. } => { CharacterState::Dance { .. } => {
anim::character::DanceAnimation::update_skeleton( anim::character::DanceAnimation::update_skeleton(
&target_base, &target_base,