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::{
|
comp::{
|
||||||
item::{Hands, ItemKind, Tool},
|
item::{Hands, ItemKind, Tool},
|
||||||
CharacterState, StateUpdate,
|
CharacterState, StateUpdate,
|
||||||
|
Body,
|
||||||
},
|
},
|
||||||
event::LocalEvent,
|
event::LocalEvent,
|
||||||
states::*,
|
states::*,
|
||||||
@ -11,10 +12,7 @@ use crate::{
|
|||||||
use vek::vec::Vec2;
|
use vek::vec::Vec2;
|
||||||
|
|
||||||
pub const MOVEMENT_THRESHOLD_VEL: f32 = 3.0;
|
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_ACCEL: f32 = 15.0;
|
||||||
const BASE_HUMANOID_AIR_SPEED: f32 = 8.0;
|
|
||||||
const BASE_HUMANOID_WATER_ACCEL: f32 = 150.0;
|
const BASE_HUMANOID_WATER_ACCEL: f32 = 150.0;
|
||||||
const BASE_HUMANOID_WATER_SPEED: f32 = 180.0;
|
const BASE_HUMANOID_WATER_SPEED: f32 = 180.0;
|
||||||
// const BASE_HUMANOID_CLIMB_ACCEL: f32 = 10.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_SPEED: f32 = 5.0;
|
||||||
// const CLIMB_COST: i32 = 5;
|
// 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`
|
/// Handles updating `Components` to move player based on state of `JoinData`
|
||||||
pub fn handle_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
|
pub fn handle_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
|
||||||
if data.physics.in_fluid {
|
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
|
/// Updates components to move player as if theyre on ground or in air
|
||||||
#[allow(clippy::assign_op_pattern)] // TODO: Pending review in #587
|
#[allow(clippy::assign_op_pattern)] // TODO: Pending review in #587
|
||||||
fn basic_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
|
fn basic_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
|
||||||
let (accel, speed): (f32, f32) = if data.physics.on_ground {
|
let accel = if data.physics.on_ground {
|
||||||
(BASE_HUMANOID_ACCEL, BASE_HUMANOID_SPEED)
|
data.body.base_accel()
|
||||||
} else {
|
} else {
|
||||||
(BASE_HUMANOID_AIR_ACCEL, BASE_HUMANOID_AIR_SPEED)
|
BASE_HUMANOID_AIR_ACCEL
|
||||||
};
|
};
|
||||||
|
|
||||||
// Move player according to move_dir
|
update.vel.0 =
|
||||||
if update.vel.0.magnitude_squared() < speed.powf(2.0) {
|
|
||||||
update.vel.0 =
|
|
||||||
update.vel.0 + Vec2::broadcast(data.dt.0) * data.inputs.move_dir * accel * efficiency;
|
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);
|
handle_orientation(data, update, 20.0);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ use vek::*;
|
|||||||
pub struct RunAnimation;
|
pub struct RunAnimation;
|
||||||
|
|
||||||
impl Animation for 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;
|
type Skeleton = QuadrupedMediumSkeleton;
|
||||||
|
|
||||||
#[cfg(feature = "use-dyn-lib")]
|
#[cfg(feature = "use-dyn-lib")]
|
||||||
@ -14,7 +14,7 @@ impl Animation for RunAnimation {
|
|||||||
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_run")]
|
#[cfg_attr(feature = "be-dyn-lib", export_name = "quadruped_medium_run")]
|
||||||
fn update_skeleton_inner(
|
fn update_skeleton_inner(
|
||||||
skeleton: &Self::Skeleton,
|
skeleton: &Self::Skeleton,
|
||||||
(velocity, orientation, last_ori, _global_time): Self::Dependency,
|
(velocity, orientation, last_ori, _global_time, avg_vel): Self::Dependency,
|
||||||
anim_time: f64,
|
anim_time: f64,
|
||||||
rate: &mut f32,
|
rate: &mut f32,
|
||||||
skeleton_attr: &SkeletonAttr,
|
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.ori = Quaternion::rotation_x(footverttfslow * 0.5 - 0.2);
|
||||||
next.foot_br.scale = Vec3::one() * 0.96;
|
next.foot_br.scale = Vec3::one() * 0.96;
|
||||||
} else {
|
} else {
|
||||||
|
let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude());
|
||||||
|
|
||||||
//Gallop
|
//Gallop
|
||||||
next.head_upper.offset =
|
next.head_upper.offset =
|
||||||
Vec3::new(0.0, skeleton_attr.head_upper.0, skeleton_attr.head_upper.1);
|
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.torso_front.1 + shortalt * 2.5,
|
||||||
) * skeleton_attr.scaler
|
) * skeleton_attr.scaler
|
||||||
/ 11.0;
|
/ 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);
|
Quaternion::rotation_x(short * 0.13) * Quaternion::rotation_z(tilt * -1.5);
|
||||||
next.torso_front.scale = Vec3::one() * skeleton_attr.scaler / 11.0;
|
next.torso_front.scale = Vec3::one() * skeleton_attr.scaler / 11.0;
|
||||||
|
|
||||||
|
@ -976,7 +976,7 @@ impl FigureMgr {
|
|||||||
// Running
|
// Running
|
||||||
(true, true, _) => anim::quadruped_medium::RunAnimation::update_skeleton(
|
(true, true, _) => anim::quadruped_medium::RunAnimation::update_skeleton(
|
||||||
&QuadrupedMediumSkeleton::new(),
|
&QuadrupedMediumSkeleton::new(),
|
||||||
(vel.0.magnitude(), ori, state.last_ori, time),
|
(vel.0.magnitude(), ori, state.last_ori, time, state.avg_vel),
|
||||||
state.state_time,
|
state.state_time,
|
||||||
&mut state_animation_rate,
|
&mut state_animation_rate,
|
||||||
skeleton_attr,
|
skeleton_attr,
|
||||||
@ -2234,6 +2234,8 @@ pub struct FigureState<S: Skeleton> {
|
|||||||
last_ori: Vec3<f32>,
|
last_ori: Vec3<f32>,
|
||||||
lpindex: u8,
|
lpindex: u8,
|
||||||
visible: bool,
|
visible: bool,
|
||||||
|
last_pos: Option<Vec3<f32>>,
|
||||||
|
avg_vel: Vec3<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Skeleton> FigureState<S> {
|
impl<S: Skeleton> FigureState<S> {
|
||||||
@ -2249,6 +2251,9 @@ impl<S: Skeleton> FigureState<S> {
|
|||||||
last_ori: Vec3::zero(),
|
last_ori: Vec3::zero(),
|
||||||
lpindex: 0,
|
lpindex: 0,
|
||||||
visible: false,
|
visible: false,
|
||||||
|
last_pos: None,
|
||||||
|
avg_vel: Vec3::zero(),
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2293,6 +2298,12 @@ impl<S: Skeleton> FigureState<S> {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.lantern_offset = lantern_offset;
|
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 }
|
pub fn locals(&self) -> &Consts<FigureLocals> { &self.locals }
|
||||||
|
Loading…
Reference in New Issue
Block a user