mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Run tilting, per-species running speed
This commit is contained in:
parent
e689de3c8a
commit
db26c10299
@ -2,6 +2,7 @@ use crate::{
|
||||
comp::{
|
||||
item::{Hands, ItemKind, Tool},
|
||||
CharacterState, StateUpdate,
|
||||
Body,
|
||||
},
|
||||
event::LocalEvent,
|
||||
states::*,
|
||||
@ -11,10 +12,7 @@ use crate::{
|
||||
use vek::vec::Vec2;
|
||||
|
||||
pub const MOVEMENT_THRESHOLD_VEL: f32 = 3.0;
|
||||
const BASE_HUMANOID_ACCEL: f32 = 100.0;
|
||||
const BASE_HUMANOID_SPEED: f32 = 170.0;
|
||||
const BASE_HUMANOID_AIR_ACCEL: f32 = 15.0;
|
||||
const BASE_HUMANOID_AIR_SPEED: f32 = 8.0;
|
||||
const BASE_HUMANOID_WATER_ACCEL: f32 = 150.0;
|
||||
const BASE_HUMANOID_WATER_SPEED: f32 = 180.0;
|
||||
// const BASE_HUMANOID_CLIMB_ACCEL: f32 = 10.0;
|
||||
@ -30,6 +28,26 @@ const BASE_HUMANOID_WATER_SPEED: f32 = 180.0;
|
||||
// const CLIMB_SPEED: f32 = 5.0;
|
||||
// const CLIMB_COST: i32 = 5;
|
||||
|
||||
impl Body {
|
||||
pub fn base_accel(&self) -> f32 {
|
||||
match self {
|
||||
Body::Humanoid(_) => 100.0,
|
||||
Body::QuadrupedSmall(_) => 80.0,
|
||||
Body::QuadrupedMedium(_) => 180.0,
|
||||
Body::BirdMedium(_) => 70.0,
|
||||
Body::FishMedium(_) => 50.0,
|
||||
Body::Dragon(_) => 250.0,
|
||||
Body::BirdSmall(_) => 75.0,
|
||||
Body::FishSmall(_) => 40.0,
|
||||
Body::BipedLarge(_) => 120.0,
|
||||
Body::Object(_) => 40.0,
|
||||
Body::Golem(_) => 130.0,
|
||||
Body::Critter(_) => 65.0,
|
||||
Body::QuadrupedLow(_) => 120.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles updating `Components` to move player based on state of `JoinData`
|
||||
pub fn handle_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
|
||||
if data.physics.in_fluid {
|
||||
@ -42,21 +60,14 @@ pub fn handle_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
|
||||
/// Updates components to move player as if theyre on ground or in air
|
||||
#[allow(clippy::assign_op_pattern)] // TODO: Pending review in #587
|
||||
fn basic_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
|
||||
let (accel, speed): (f32, f32) = if data.physics.on_ground {
|
||||
(BASE_HUMANOID_ACCEL, BASE_HUMANOID_SPEED)
|
||||
let accel = if data.physics.on_ground {
|
||||
data.body.base_accel()
|
||||
} else {
|
||||
(BASE_HUMANOID_AIR_ACCEL, BASE_HUMANOID_AIR_SPEED)
|
||||
BASE_HUMANOID_AIR_ACCEL
|
||||
};
|
||||
|
||||
// Move player according to move_dir
|
||||
if update.vel.0.magnitude_squared() < speed.powf(2.0) {
|
||||
update.vel.0 =
|
||||
update.vel.0 =
|
||||
update.vel.0 + Vec2::broadcast(data.dt.0) * data.inputs.move_dir * accel * efficiency;
|
||||
let mag2 = update.vel.0.magnitude_squared();
|
||||
if mag2 > speed.powf(2.0) {
|
||||
update.vel.0 = update.vel.0.normalized() * speed;
|
||||
}
|
||||
}
|
||||
|
||||
handle_orientation(data, update, 20.0);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use vek::*;
|
||||
pub struct RunAnimation;
|
||||
|
||||
impl Animation for RunAnimation {
|
||||
type Dependency = (f32, Vec3<f32>, Vec3<f32>, f64);
|
||||
type Dependency = (f32, Vec3<f32>, Vec3<f32>, f64, Vec3<f32>);
|
||||
type Skeleton = QuadrupedMediumSkeleton;
|
||||
|
||||
#[cfg(feature = "use-dyn-lib")]
|
||||
@ -14,7 +14,7 @@ impl Animation for RunAnimation {
|
||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_run")]
|
||||
fn update_skeleton_inner(
|
||||
skeleton: &Self::Skeleton,
|
||||
(velocity, orientation, last_ori, _global_time): Self::Dependency,
|
||||
(velocity, orientation, last_ori, _global_time, avg_vel): Self::Dependency,
|
||||
anim_time: f64,
|
||||
rate: &mut f32,
|
||||
skeleton_attr: &SkeletonAttr,
|
||||
@ -191,6 +191,8 @@ impl Animation for RunAnimation {
|
||||
next.foot_br.ori = Quaternion::rotation_x(footverttfslow * 0.5 - 0.2);
|
||||
next.foot_br.scale = Vec3::one() * 0.96;
|
||||
} else {
|
||||
let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude());
|
||||
|
||||
//Gallop
|
||||
next.head_upper.offset =
|
||||
Vec3::new(0.0, skeleton_attr.head_upper.0, skeleton_attr.head_upper.1);
|
||||
@ -219,7 +221,7 @@ impl Animation for RunAnimation {
|
||||
skeleton_attr.torso_front.1 + shortalt * 2.5,
|
||||
) * skeleton_attr.scaler
|
||||
/ 11.0;
|
||||
next.torso_front.ori =
|
||||
next.torso_front.ori = Quaternion::rotation_x(x_tilt) *
|
||||
Quaternion::rotation_x(short * 0.13) * Quaternion::rotation_z(tilt * -1.5);
|
||||
next.torso_front.scale = Vec3::one() * skeleton_attr.scaler / 11.0;
|
||||
|
||||
|
@ -976,7 +976,7 @@ impl FigureMgr {
|
||||
// Running
|
||||
(true, true, _) => anim::quadruped_medium::RunAnimation::update_skeleton(
|
||||
&QuadrupedMediumSkeleton::new(),
|
||||
(vel.0.magnitude(), ori, state.last_ori, time),
|
||||
(vel.0.magnitude(), ori, state.last_ori, time, state.avg_vel),
|
||||
state.state_time,
|
||||
&mut state_animation_rate,
|
||||
skeleton_attr,
|
||||
@ -2234,6 +2234,8 @@ pub struct FigureState<S: Skeleton> {
|
||||
last_ori: Vec3<f32>,
|
||||
lpindex: u8,
|
||||
visible: bool,
|
||||
last_pos: Option<Vec3<f32>>,
|
||||
avg_vel: Vec3<f32>,
|
||||
}
|
||||
|
||||
impl<S: Skeleton> FigureState<S> {
|
||||
@ -2249,6 +2251,9 @@ impl<S: Skeleton> FigureState<S> {
|
||||
last_ori: Vec3::zero(),
|
||||
lpindex: 0,
|
||||
visible: false,
|
||||
last_pos: None,
|
||||
avg_vel: Vec3::zero(),
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -2293,6 +2298,12 @@ impl<S: Skeleton> FigureState<S> {
|
||||
)
|
||||
.unwrap();
|
||||
self.lantern_offset = lantern_offset;
|
||||
|
||||
let smoothing = (5.0 * dt).min(1.0);
|
||||
if let Some(last_pos) = self.last_pos {
|
||||
self.avg_vel = (1.0 - smoothing) * self.avg_vel + smoothing * (pos - last_pos) * dt;
|
||||
}
|
||||
self.last_pos = Some(pos);
|
||||
}
|
||||
|
||||
pub fn locals(&self) -> &Consts<FigureLocals> { &self.locals }
|
||||
|
Loading…
Reference in New Issue
Block a user