Fix GlideWield overriding state changes

This commit is contained in:
Ludvig Böklin 2021-06-22 11:20:40 +02:00
parent 2165fc7d2e
commit eddc967462

View File

@ -32,29 +32,32 @@ impl CharacterBehavior for Data {
handle_dodge_input(data, &mut update);
handle_wield(data, &mut update);
let mut glider = self.0;
glider.ori = glider.ori.slerped_towards(
Ori::from(data.inputs.look_dir)
.yawed_towards(data.ori.look_dir())
.pitched_up(inline_tweak::tweak!(0.5)),
inline_tweak::tweak!(5.0) * data.dt.0,
);
// If still in this state, do the things
if matches!(update.character, CharacterState::GlideWield(_)) {
let mut glider = self.0;
glider.ori = glider.ori.slerped_towards(
Ori::from(data.inputs.look_dir)
.yawed_towards(data.ori.look_dir())
.pitched_up(inline_tweak::tweak!(0.5)),
inline_tweak::tweak!(5.0) * data.dt.0,
);
// If not on the ground while wielding glider enter gliding state
update.character = if !data.physics.on_ground {
CharacterState::Glide(glide::Data::new(glider))
} else if data
.physics
.in_liquid()
.map(|depth| depth > 0.5)
.unwrap_or(false)
{
CharacterState::Idle
} else if data.inventory.equipped(EquipSlot::Glider).is_none() {
CharacterState::Idle
} else {
CharacterState::GlideWield(Self(glider))
};
// If not on the ground while wielding glider enter gliding state
update.character = if !data.physics.on_ground {
CharacterState::Glide(glide::Data::new(glider))
} else if data
.physics
.in_liquid()
.map(|depth| depth > 0.5)
.unwrap_or(false)
{
CharacterState::Idle
} else if data.inventory.equipped(EquipSlot::Glider).is_none() {
CharacterState::Idle
} else {
CharacterState::GlideWield(Self(glider))
};
}
update
}