Fix gliderwield downhill run jitter

This commit is contained in:
Ludvig Böklin 2021-08-01 11:20:46 +00:00 committed by Marcel
parent f51c4ed860
commit 400734cc0a
9 changed files with 41 additions and 26 deletions

View File

@ -63,6 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Campfires now despawn when underwater
- Players no longer spawn underground if their waypoint is underground
- Map will now zoom around the cursor's position and drag correctly
- No more jittering while running down slopes with the glider out
## [0.10.0] - 2021-06-12

View File

@ -1231,7 +1231,7 @@ impl Client {
.map(|cs| {
matches!(
cs,
comp::CharacterState::GlideWield | comp::CharacterState::Glide(_)
comp::CharacterState::GlideWield(_) | comp::CharacterState::Glide(_)
)
});

View File

@ -59,7 +59,7 @@ pub enum CharacterState {
Talk,
Sneak,
Glide(glide::Data),
GlideWield,
GlideWield(glide_wield::Data),
/// A stunned state
Stunned(stunned::Data),
/// A basic blocking state
@ -189,7 +189,7 @@ impl CharacterState {
| CharacterState::Equipping(_)
| CharacterState::Dance
| CharacterState::Glide(_)
| CharacterState::GlideWield
| CharacterState::GlideWield(_)
| CharacterState::Talk
| CharacterState::Roll(_),
)
@ -228,7 +228,7 @@ impl CharacterState {
CharacterState::Talk => states::talk::Data.behavior(j),
CharacterState::Climb(data) => data.behavior(j),
CharacterState::Glide(data) => data.behavior(j),
CharacterState::GlideWield => states::glide_wield::Data.behavior(j),
CharacterState::GlideWield(data) => data.behavior(j),
CharacterState::Stunned(data) => data.behavior(j),
CharacterState::Sit => states::sit::Data::behavior(&states::sit::Data, j),
CharacterState::Dance => states::dance::Data::behavior(&states::dance::Data, j),
@ -264,7 +264,7 @@ impl CharacterState {
CharacterState::Talk => states::talk::Data.handle_event(j, action),
CharacterState::Climb(data) => data.handle_event(j, action),
CharacterState::Glide(data) => data.handle_event(j, action),
CharacterState::GlideWield => states::glide_wield::Data.handle_event(j, action),
CharacterState::GlideWield(data) => data.handle_event(j, action),
CharacterState::Stunned(data) => data.handle_event(j, action),
CharacterState::Sit => states::sit::Data::handle_event(&states::sit::Data, j, action),
CharacterState::Dance => {

View File

@ -4,7 +4,10 @@ use crate::{
fluid_dynamics::angle_of_attack, inventory::slot::EquipSlot, CharacterState, Ori,
StateUpdate, Vel,
},
states::behavior::{CharacterBehavior, JoinData},
states::{
behavior::{CharacterBehavior, JoinData},
glide_wield,
},
util::{Dir, Plane, Projection},
};
use serde::{Deserialize, Serialize};
@ -77,8 +80,7 @@ impl CharacterBehavior for Data {
if data.physics.on_ground.is_some()
&& (data.vel.0 - data.physics.ground_vel).magnitude_squared() < 2_f32.powi(2)
{
update.character = CharacterState::GlideWield;
update.ori = update.ori.to_horizontal();
update.character = CharacterState::GlideWield(glide_wield::Data::default());
} else if data.physics.in_liquid().is_some()
|| data
.inventory
@ -86,7 +88,6 @@ impl CharacterBehavior for Data {
.is_none()
{
update.character = CharacterState::Idle;
update.ori = update.ori.to_horizontal();
} else if !handle_climb(data, &mut update) {
let air_flow = data
.physics
@ -193,8 +194,6 @@ impl CharacterBehavior for Data {
inputs_disabled,
..*self
});
} else {
update.ori = update.ori.to_horizontal();
}
update
@ -203,7 +202,6 @@ impl CharacterBehavior for Data {
fn unwield(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data);
update.character = CharacterState::Idle;
update.ori = update.ori.to_horizontal();
update
}
}

View File

@ -6,8 +6,18 @@ use crate::{
glide,
},
};
use serde::{Deserialize, Serialize};
pub struct Data;
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Data {
// time since left ground, for preventing state transition
// before block snapping kicks in
timer: f32,
}
impl Default for Data {
fn default() -> Self { Self { timer: 0.0 } }
}
impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate {
@ -21,7 +31,13 @@ impl CharacterBehavior for Data {
// If not on the ground while wielding glider enter gliding state
if data.physics.on_ground.is_none() {
update.character = CharacterState::Glide(glide::Data::new(10.0, 0.6, *data.ori));
update.character = if self.timer > 0.3 {
CharacterState::Glide(glide::Data::new(10.0, 0.6, *data.ori))
} else {
CharacterState::GlideWield(Self {
timer: self.timer + data.dt.0,
})
};
}
if data
.physics

View File

@ -639,7 +639,7 @@ pub fn attempt_glide_wield(data: &JoinData<'_>, update: &mut StateUpdate) {
.unwrap_or(false)
&& data.body.is_humanoid()
{
update.character = CharacterState::GlideWield;
update.character = CharacterState::GlideWield(glide_wield::Data::default());
}
}

View File

@ -24,11 +24,11 @@
"rustOverlay": "rustOverlay"
},
"locked": {
"lastModified": 1625378930,
"narHash": "sha256-iBnCmrLweBmtN9VkG6AX4wSE5UUF//4VtfX6Ebhbaew=",
"lastModified": 1627752074,
"narHash": "sha256-iuOGIbJC4hn1XqwrBjiol6j0Xj+AImND6Z9fP/6Za74=",
"owner": "yusdacra",
"repo": "nix-cargo-integration",
"rev": "4d6efcfd0bc6c6235b180837257ab8020f108c23",
"rev": "47e6414440c66bfd44a0ea07d64ca62075470f62",
"type": "github"
},
"original": {
@ -39,11 +39,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1625375231,
"narHash": "sha256-dbp2RRftypbAYad/xhDBBG0N7s1WQW+T4jazimvtvRo=",
"lastModified": 1627533199,
"narHash": "sha256-NyIUcNevwtsMBINn56jnDF8wz3TV1AFxw+Vw6JMnkyE=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8aff53d3cf23b5eb67c0ba9ba2392d694ade3930",
"rev": "dd98b100651cfbb8804f32d852f75ef7c97a6b74",
"type": "github"
},
"original": {
@ -62,11 +62,11 @@
"rustOverlay": {
"flake": false,
"locked": {
"lastModified": 1625364738,
"narHash": "sha256-TPlpEcywGnB8jNIPOlCqFVbioskGOpasrVhxdw0BHzA=",
"lastModified": 1627697717,
"narHash": "sha256-ij7rk2VkPpNf0NTbpP5jfbwuIWfrLXN00pZ+pizGnGM=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "f08a653d9d6bbf06b5cc5dd1e570f1c449acbcf3",
"rev": "6d957c2105a5a548211c412fbc97bae81b7b8eb6",
"type": "github"
},
"original": {

View File

@ -291,7 +291,7 @@ impl<'a> System<'a> for Sys {
let is_gliding = matches!(
read_data.char_states.get(entity),
Some(CharacterState::GlideWield | CharacterState::Glide(_))
Some(CharacterState::GlideWield(_) | CharacterState::Glide(_))
) && physics_state.on_ground.is_none();
if let Some(pid) = agent.position_pid_controller.as_mut() {

View File

@ -24,7 +24,7 @@ pub fn draw_char_state_group(
CharacterState::Dance
| CharacterState::Idle
| CharacterState::Sit
| CharacterState::GlideWield
| CharacterState::GlideWield(_)
| CharacterState::Sneak
| CharacterState::Talk
| CharacterState::Wielding => {},