Merge branch 'humanoid_ai_glide_when_falling' into 'master'

FIX #956: Humanoid ai glide when falling

See merge request veloren/veloren!1772
This commit is contained in:
Joshua Barretto 2021-02-22 00:57:25 +00:00
commit e2290783fc
3 changed files with 39 additions and 3 deletions

View File

@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Changed crafting recipes involving shiny gems to use diamonds instead.
- Cave scatter now includes all 6 gems.
- Adjusted Stonework Defender loot table to remove mindflayer drops (bag, staff, glider).
- Made humanoid NPCs use gliders (if equipped) when falling
- Changed default controller key bindings
- Improved network efficiency by ≈ factor 10 by using tokio.
- Added item tooltips to trade window.

View File

@ -316,6 +316,9 @@ impl LoadoutBuilder {
0 => Some(Item::new_from_asset_expect("common.items.lantern.black_0")),
_ => None,
})
.glider(Some(Item::new_from_asset_expect(
"common.items.glider.glider_starter",
)))
.build(),
Bandit => LoadoutBuilder::new()
.active_item(active_item)
@ -341,6 +344,9 @@ impl LoadoutBuilder {
0 => Some(Item::new_from_asset_expect("common.items.lantern.black_0")),
_ => None,
})
.glider(Some(Item::new_from_asset_expect(
"common.items.glider.glider_starter",
)))
.build(),
CultistNovice => LoadoutBuilder::new()
.active_item(active_item)
@ -369,6 +375,9 @@ impl LoadoutBuilder {
0 => Some(Item::new_from_asset_expect("common.items.lantern.black_0")),
_ => None,
})
.glider(Some(Item::new_from_asset_expect(
"common.items.glider.glider_blue",
)))
.build(),
CultistAcolyte => LoadoutBuilder::new()
.active_item(active_item)
@ -397,6 +406,9 @@ impl LoadoutBuilder {
0 => Some(Item::new_from_asset_expect("common.items.lantern.black_0")),
_ => None,
})
.glider(Some(Item::new_from_asset_expect(
"common.items.glider.glider_blue",
)))
.build(),
Warlord => LoadoutBuilder::new()
.active_item(active_item)
@ -425,6 +437,9 @@ impl LoadoutBuilder {
0 => Some(Item::new_from_asset_expect("common.items.lantern.black_0")),
_ => None,
})
.glider(Some(Item::new_from_asset_expect(
"common.items.glider.glider_cultist",
)))
.build(),
Warlock => LoadoutBuilder::new()
.active_item(active_item)
@ -453,6 +468,9 @@ impl LoadoutBuilder {
0 => Some(Item::new_from_asset_expect("common.items.lantern.black_0")),
_ => None,
})
.glider(Some(Item::new_from_asset_expect(
"common.items.glider.glider_cultist",
)))
.build(),
Villager => LoadoutBuilder::new()
.active_item(active_item)

View File

@ -166,6 +166,12 @@ impl<'a> System<'a> for Sys {
alignment.copied()
};
let glider_equipped = inventory.equipped(EquipSlot::Glider).as_ref().map_or(false, |item| {
matches!(item.kind(), comp::item::ItemKind::Glider(_))
});
let is_gliding = matches!(char_states.get(entity), Some(CharacterState::GlideWield) | Some(CharacterState::Glide)) && !physics_state.on_ground;
controller.reset();
let mut event_emitter = event_bus.emitter();
// Light lanterns at night
@ -374,7 +380,7 @@ impl<'a> System<'a> for Sys {
}
// Put away weapon
if thread_rng().gen::<f32>() < 0.005 {
if thread_rng().gen::<f32>() < 0.005 && matches!(char_states.get(entity), Some(CharacterState::Wielding)) {
controller.actions.push(ControlAction::Unwield);
}
@ -384,7 +390,9 @@ impl<'a> System<'a> for Sys {
}
}
controller.actions.push(ControlAction::Unwield);
if physics_state.on_ground {
controller.actions.push(ControlAction::Unwield);
}
// Sometimes try searching for new targets
if thread_rng().gen::<f32>() < 0.1 {
@ -439,7 +447,7 @@ impl<'a> System<'a> for Sys {
timer,
} => {
if let Some(body) = body {
if body.can_strafe() {
if body.can_strafe() && !is_gliding { // Keep glider open if already gliding
controller.actions.push(ControlAction::Unwield);
}
}
@ -1437,6 +1445,15 @@ impl<'a> System<'a> for Sys {
}
}
if glider_equipped && !physics_state.on_ground {
if let Some(velocity) = velocities.get(entity) {
// toggle glider when vertical velocity is above some threshold (here ~ glider fall vertical speed)
if velocity.0.z < -26.0 {
controller.actions.push(ControlAction::GlideWield);
}
}
}
if do_idle {
agent.activity = Activity::Idle {
bearing: Vec2::zero(),