From 7a73e4240bd415f1420540ce2eeb22eae68b624a Mon Sep 17 00:00:00 2001 From: Snowram Date: Thu, 16 Sep 2021 01:25:00 +0200 Subject: [PATCH] Bird large beam offset hack --- common/src/comp/inventory/loadout_builder.rs | 9 ++--- common/src/states/basic_beam.rs | 35 ++++++++++++++++---- server/src/sys/agent.rs | 3 ++ voxygen/anim/src/bird_large/breathe.rs | 16 +++++---- voxygen/anim/src/bird_large/mod.rs | 5 +-- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/common/src/comp/inventory/loadout_builder.rs b/common/src/comp/inventory/loadout_builder.rs index 5af8102058..24446d138d 100644 --- a/common/src/comp/inventory/loadout_builder.rs +++ b/common/src/comp/inventory/loadout_builder.rs @@ -343,18 +343,15 @@ fn default_main_tool(body: &Body) -> Item { )), }, Body::BirdLarge(bird_large) => match (bird_large.species, bird_large.body_type) { - (bird_large::Species::Cockatrice, _) => Some(Item::new_from_asset_expect( - "common.items.npc_weapons.unique.birdlargebreathe", - )), + (bird_large::Species::Cockatrice | bird_large::Species::FlameWyvern, _) => Some( + Item::new_from_asset_expect("common.items.npc_weapons.unique.birdlargebreathe"), + ), (bird_large::Species::Phoenix, _) => Some(Item::new_from_asset_expect( "common.items.npc_weapons.unique.birdlargefire", )), (bird_large::Species::Roc, _) => Some(Item::new_from_asset_expect( "common.items.npc_weapons.unique.birdlargebasic", )), - (bird_large::Species::FlameWyvern, _) => Some(Item::new_from_asset_expect( - "common.items.npc_weapons.unique.birdlargebreathe", - )), }, _ => None, }; diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index d67604fdc9..ffa0e2f14c 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -12,6 +12,7 @@ use crate::{ behavior::{CharacterBehavior, JoinData}, utils::*, }, + terrain::Block, uid::Uid, util::Dir, }; @@ -160,9 +161,16 @@ impl CharacterBehavior for Data { )) .prerotated(pitch) }; + // Velocity relative to the current ground + let rel_vel = data.vel.0 - data.physics.ground_vel; // Gets offsets - let body_offsets = - beam_offsets(data.body, data.inputs.look_dir, update.ori.look_vec()); + let body_offsets = beam_offsets( + data.body, + data.inputs.look_dir, + update.ori.look_vec(), + rel_vel, + data.physics.on_ground, + ); let pos = Pos(data.pos.0 + body_offsets); // Create beam segment @@ -219,9 +227,17 @@ impl CharacterBehavior for Data { } } -fn height_offset(body: &Body, look_dir: Dir) -> f32 { +fn height_offset(body: &Body, look_dir: Dir, velocity: Vec3, on_ground: Option) -> f32 { match body { - Body::BirdLarge(_) => body.height() * 0.8, + // Hack to make the beam offset correspond to the animation + Body::BirdLarge(_) => { + body.height() * 0.3 + + if on_ground.is_none() { + (2.0 - velocity.xy().magnitude() * 0.25).max(-1.0) + } else { + 0.0 + } + }, Body::Golem(_) => { const DIR_COEFF: f32 = 2.0; body.height() * 0.9 + look_dir.z * DIR_COEFF @@ -234,10 +250,15 @@ fn height_offset(body: &Body, look_dir: Dir) -> f32 { } } -pub fn beam_offsets(body: &Body, look_dir: Dir, ori: Vec3) -> Vec3 { +pub fn beam_offsets( + body: &Body, + look_dir: Dir, + ori: Vec3, + velocity: Vec3, + on_ground: Option, +) -> Vec3 { let body_radius = body.min_radius(); - let body_offsets_z = height_offset(body, look_dir); - + let body_offsets_z = height_offset(body, look_dir, velocity, on_ground); Vec3::new( body_radius * ori.x * 1.1, body_radius * ori.y * 1.1, diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 9aaaaa94e9..bab6cdb37b 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -1884,6 +1884,9 @@ impl<'a> AgentData<'a> { body, controller.inputs.look_dir, self.ori.look_vec(), + // Try to match animation by getting some context + self.vel.0 - self.physics_state.ground_vel, + self.physics_state.on_ground, ) }); let aim_to = Vec3::new( diff --git a/voxygen/anim/src/bird_large/breathe.rs b/voxygen/anim/src/bird_large/breathe.rs index 224369283e..1c5708d4d9 100644 --- a/voxygen/anim/src/bird_large/breathe.rs +++ b/voxygen/anim/src/bird_large/breathe.rs @@ -106,14 +106,16 @@ impl Animation for BreatheAnimation { next.tail_rear.orientation = Quaternion::rotation_x(-movement1abs * 0.1 + movement2abs * 0.1 + twitch2 * -0.2); } else { - if velocity.xy().magnitude() < 1.0 { - next.neck.orientation = - Quaternion::rotation_x(movement1abs * -0.4 - movement2abs * 0.5); + next.neck.orientation = Quaternion::rotation_x( + movement1abs * -0.4 + + movement2abs * (-0.5 + velocity.xy().magnitude() * 0.2).min(0.0), + ); - next.head.orientation = Quaternion::rotation_x( - movement1abs * 0.5 - movement2abs * 0.5 + look_dir.z * 0.4, - ); - }; + next.head.orientation = Quaternion::rotation_x( + movement1abs * 0.5 + + movement2abs * (-0.5 + velocity.xy().magnitude() * 0.2).min(0.0) + + look_dir.z * 0.4, + ); } next diff --git a/voxygen/anim/src/bird_large/mod.rs b/voxygen/anim/src/bird_large/mod.rs index b8363215e3..31569d6fd8 100644 --- a/voxygen/anim/src/bird_large/mod.rs +++ b/voxygen/anim/src/bird_large/mod.rs @@ -241,10 +241,7 @@ impl<'a> From<&'a Body> for SkeletonAttr { (Roc, _) => (-0.4), (FlameWyvern, _) => (-0.65), }, - wyvern: match (body.species, body.body_type) { - (FlameWyvern, _) => true, - _ => false, - }, + wyvern: matches!((body.species, body.body_type), (FlameWyvern, _)), } } }