From 8a83ecf57fdced7a2b1239bcf8f0437ba9a88cbd Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Thu, 5 Aug 2021 02:14:10 +0300 Subject: [PATCH] Fix Beam orientation, remove orientation_behavior * make old OrientationBehavior::FromOri default behaviour * use rotation formed from look_dir instead of constructing ori on the fly (which is altered after normalization). --- .../abilities/custom/basilisk/petrify.ron | 1 - .../custom/birdlargebreathe/flamethrower.ron | 1 - .../custom/birdlargefire/flamethrower.ron | 1 - .../abilities/custom/claygolem/laser.ron | 1 - .../abilities/custom/harvester/firebreath.ron | 1 - .../custom/mindflayer/cursedflames.ron | 1 - .../custom/quadlowbeam/lifestealbeam.ron | 1 - .../custom/quadlowbreathe/flamethrower.ron | 1 - .../abilities/custom/tidalwarrior/bubbles.ron | 1 - .../abilities/custom/turret/flamethrower.ron | 1 - .../abilities/custom/yeti/frostbreath.ron | 1 - .../abilities/sceptre/lifestealbeam.ron | 1 - .../common/abilities/staff/flamethrower.ron | 1 - .../abilities/staffsimple/flamethrower.ron | 1 - common/src/comp/ability.rs | 4 -- common/src/states/basic_beam.rs | 54 +++++++++---------- 16 files changed, 24 insertions(+), 48 deletions(-) diff --git a/assets/common/abilities/custom/basilisk/petrify.ron b/assets/common/abilities/custom/basilisk/petrify.ron index 20b6022fb7..3ef55daf04 100644 --- a/assets/common/abilities/custom/basilisk/petrify.ron +++ b/assets/common/abilities/custom/basilisk/petrify.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 0, energy_drain: 0, - orientation_behavior: Normal, ori_rate: 0.3, specifier: Cultist, ) diff --git a/assets/common/abilities/custom/birdlargebreathe/flamethrower.ron b/assets/common/abilities/custom/birdlargebreathe/flamethrower.ron index dfbd2227dc..cf3e4c63b6 100644 --- a/assets/common/abilities/custom/birdlargebreathe/flamethrower.ron +++ b/assets/common/abilities/custom/birdlargebreathe/flamethrower.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 0, energy_drain: 0, - orientation_behavior: Normal, ori_rate: 0.3, specifier: Flamethrower, ) diff --git a/assets/common/abilities/custom/birdlargefire/flamethrower.ron b/assets/common/abilities/custom/birdlargefire/flamethrower.ron index dfbd2227dc..cf3e4c63b6 100644 --- a/assets/common/abilities/custom/birdlargefire/flamethrower.ron +++ b/assets/common/abilities/custom/birdlargefire/flamethrower.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 0, energy_drain: 0, - orientation_behavior: Normal, ori_rate: 0.3, specifier: Flamethrower, ) diff --git a/assets/common/abilities/custom/claygolem/laser.ron b/assets/common/abilities/custom/claygolem/laser.ron index c93f0f7ce8..95782454f0 100644 --- a/assets/common/abilities/custom/claygolem/laser.ron +++ b/assets/common/abilities/custom/claygolem/laser.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 50, energy_drain: 0, - orientation_behavior: FromOri, ori_rate: 0.07, specifier: ClayGolem, ) diff --git a/assets/common/abilities/custom/harvester/firebreath.ron b/assets/common/abilities/custom/harvester/firebreath.ron index 94f0a66de4..ac52ce7561 100644 --- a/assets/common/abilities/custom/harvester/firebreath.ron +++ b/assets/common/abilities/custom/harvester/firebreath.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 0, energy_drain: 0, - orientation_behavior: Normal, ori_rate: 0.2, specifier: Flamethrower, ) diff --git a/assets/common/abilities/custom/mindflayer/cursedflames.ron b/assets/common/abilities/custom/mindflayer/cursedflames.ron index b74005d138..8ce5a5cfb5 100644 --- a/assets/common/abilities/custom/mindflayer/cursedflames.ron +++ b/assets/common/abilities/custom/mindflayer/cursedflames.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 0, energy_drain: 0, - orientation_behavior: FromOri, ori_rate: 0.2, specifier: Cultist, ) diff --git a/assets/common/abilities/custom/quadlowbeam/lifestealbeam.ron b/assets/common/abilities/custom/quadlowbeam/lifestealbeam.ron index 97262f80f0..bf9f67567c 100644 --- a/assets/common/abilities/custom/quadlowbeam/lifestealbeam.ron +++ b/assets/common/abilities/custom/quadlowbeam/lifestealbeam.ron @@ -9,7 +9,6 @@ BasicBeam( damage_effect: Some(Lifesteal(0.15)), energy_regen: 25, energy_drain: 0, - orientation_behavior: Normal, ori_rate: 0.3, specifier: LifestealBeam, ) diff --git a/assets/common/abilities/custom/quadlowbreathe/flamethrower.ron b/assets/common/abilities/custom/quadlowbreathe/flamethrower.ron index 5f4dab269a..5d6fd2895e 100644 --- a/assets/common/abilities/custom/quadlowbreathe/flamethrower.ron +++ b/assets/common/abilities/custom/quadlowbreathe/flamethrower.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 0, energy_drain: 0, - orientation_behavior: Normal, ori_rate: 0.3, specifier: Flamethrower, ) diff --git a/assets/common/abilities/custom/tidalwarrior/bubbles.ron b/assets/common/abilities/custom/tidalwarrior/bubbles.ron index a34d1cb777..3d35c86f50 100644 --- a/assets/common/abilities/custom/tidalwarrior/bubbles.ron +++ b/assets/common/abilities/custom/tidalwarrior/bubbles.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 0, energy_drain: 0, - orientation_behavior: Normal, ori_rate: 0.3, specifier: Bubbles, ) diff --git a/assets/common/abilities/custom/turret/flamethrower.ron b/assets/common/abilities/custom/turret/flamethrower.ron index 33f5dc51c9..da84dd0160 100644 --- a/assets/common/abilities/custom/turret/flamethrower.ron +++ b/assets/common/abilities/custom/turret/flamethrower.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 0, energy_drain: 0, - orientation_behavior: Normal, ori_rate: 0.3, specifier: Flamethrower, ) diff --git a/assets/common/abilities/custom/yeti/frostbreath.ron b/assets/common/abilities/custom/yeti/frostbreath.ron index 7f35a26ae7..2f29bf5e94 100644 --- a/assets/common/abilities/custom/yeti/frostbreath.ron +++ b/assets/common/abilities/custom/yeti/frostbreath.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 0, energy_drain: 0, - orientation_behavior: FromOri, ori_rate: 0.1, specifier: Frost, ) diff --git a/assets/common/abilities/sceptre/lifestealbeam.ron b/assets/common/abilities/sceptre/lifestealbeam.ron index 5236219eb4..7d37405d23 100644 --- a/assets/common/abilities/sceptre/lifestealbeam.ron +++ b/assets/common/abilities/sceptre/lifestealbeam.ron @@ -9,7 +9,6 @@ BasicBeam( damage_effect: Some(Lifesteal(0.125)), energy_regen: 50, energy_drain: 0, - orientation_behavior: Normal, ori_rate: 0.3, specifier: LifestealBeam ) diff --git a/assets/common/abilities/staff/flamethrower.ron b/assets/common/abilities/staff/flamethrower.ron index 8f5c80ac0a..aefa0236b8 100644 --- a/assets/common/abilities/staff/flamethrower.ron +++ b/assets/common/abilities/staff/flamethrower.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 0, energy_drain: 350, - orientation_behavior: Normal, ori_rate: 0.3, specifier: Flamethrower, ) diff --git a/assets/common/abilities/staffsimple/flamethrower.ron b/assets/common/abilities/staffsimple/flamethrower.ron index b024bae2e4..d676f32c10 100644 --- a/assets/common/abilities/staffsimple/flamethrower.ron +++ b/assets/common/abilities/staffsimple/flamethrower.ron @@ -14,7 +14,6 @@ BasicBeam( ))), energy_regen: 0, energy_drain: 350, - orientation_behavior: FromOri, ori_rate: 0.3, specifier: Flamethrower, ) diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index 44241a7607..3295e3b821 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -251,7 +251,6 @@ pub enum CharacterAbility { damage_effect: Option, energy_regen: f32, energy_drain: f32, - orientation_behavior: basic_beam::OrientationBehavior, ori_rate: f32, specifier: beam::FrontendSpecifier, }, @@ -745,7 +744,6 @@ impl CharacterAbility { ref mut damage_effect, energy_regen: _, ref mut energy_drain, - orientation_behavior: _, ori_rate: _, specifier: _, } => { @@ -1878,7 +1876,6 @@ impl From<(&CharacterAbility, AbilityInfo, &JoinData<'_>)> for CharacterState { damage_effect, energy_regen, energy_drain, - orientation_behavior, ori_rate, specifier, } => CharacterState::BasicBeam(basic_beam::Data { @@ -1894,7 +1891,6 @@ impl From<(&CharacterAbility, AbilityInfo, &JoinData<'_>)> for CharacterState { energy_regen: *energy_regen, energy_drain: *energy_drain, ability_info, - orientation_behavior: *orientation_behavior, ori_rate: *ori_rate, specifier: *specifier, }, diff --git a/common/src/states/basic_beam.rs b/common/src/states/basic_beam.rs index 31080f42c0..0d1e1025f5 100644 --- a/common/src/states/basic_beam.rs +++ b/common/src/states/basic_beam.rs @@ -10,6 +10,7 @@ use crate::{ utils::*, }, uid::Uid, + util::Dir, }; use serde::{Deserialize, Serialize}; use std::time::Duration; @@ -38,8 +39,6 @@ pub struct StaticData { pub energy_regen: f32, /// Energy drained per second pub energy_drain: f32, - /// Used to dictate how orientation functions in this state - pub orientation_behavior: OrientationBehavior, /// How fast enemy can rotate with beam pub ori_rate: f32, /// What key is used to press ability @@ -64,9 +63,6 @@ impl CharacterBehavior for Data { let mut update = StateUpdate::from(data); let ori_rate = self.static_data.ori_rate; - if self.static_data.orientation_behavior == OrientationBehavior::Turret { - update.ori = Ori::from(data.inputs.look_dir); - } handle_orientation(data, &mut update, ori_rate); handle_move(data, &mut update, 0.4); @@ -142,16 +138,25 @@ impl CharacterBehavior for Data { Body::Golem(_) => data.body.height() * 0.9 + data.inputs.look_dir.z * 3.0, _ => data.body.height() * 0.5, }; - let (body_offsets, ori) = match self.static_data.orientation_behavior { - OrientationBehavior::Normal | OrientationBehavior::Turret => ( - Vec3::new( - body_offsets_r * data.inputs.look_dir.x, - body_offsets_r * data.inputs.look_dir.y, - body_offsets_z, - ), - Ori::from(data.inputs.look_dir), - ), - OrientationBehavior::FromOri => ( + let (body_offsets, ori) = { + // We want Beam to use Ori. + // But we also want beam to use Z part of where you look. + // This means that we need to merge this data to one Ori. + // + // This code just gets look_dir without Z part + // and normalizes it. This is what `xy_dir is`. + // + // Then we find rotation between xy_dir and look_dir + // which gives us quaternion how of what rotation we need + // to do to get Z part we want. + // + // Then we construct Ori without Z part + // and applying `pitch` to get needed orientation. + let look_dir = data.inputs.look_dir; + let xy_dir = Dir::from_unnormalized(Vec3::new(look_dir.x, look_dir.y, 0.0)) + .unwrap_or_else(Dir::default); + let pitch = xy_dir.rotation_between(look_dir); + ( Vec3::new( body_offsets_r * update.ori.look_vec().x, body_offsets_r * update.ori.look_vec().y, @@ -160,9 +165,10 @@ impl CharacterBehavior for Data { Ori::from(Vec3::new( update.ori.look_vec().x, update.ori.look_vec().y, - data.inputs.look_dir.z, - )), - ), + 0.0, + )) + .prerotated(pitch), + ) }; let pos = Pos(data.pos.0 + body_offsets); // Create beam segment @@ -218,15 +224,3 @@ impl CharacterBehavior for Data { update } } - -#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] -pub enum OrientationBehavior { - /// Uses look_dir as direction of beam - Normal, - /// Uses look_dir as direction of beam, sets orientation to same direction - /// as look_dir - Turret, - /// Uses orientation x and y and look_dir z as direction of beam (z from - /// look_dir as orientation will only go through 2d rotations naturally) - FromOri, -}