Various fixes to beam, body based interp

This commit is contained in:
Snowram 2021-01-25 19:33:43 +01:00
parent 11050a05ce
commit f25b2b1500
7 changed files with 43 additions and 34 deletions

View File

@ -11,5 +11,5 @@ BasicBeam(
energy_regen: 0,
energy_cost: 0,
energy_drain: 0,
orientation_behavior: Turret(5.0),
orientation_behavior: Turret,
)

View File

@ -225,7 +225,7 @@ pub enum CharacterAbility {
energy_regen: u32,
energy_cost: u32,
energy_drain: u32,
orientation_behavior: basic_beam::OrientationBehavior,
orientation_behavior: basic_beam::MovementBehavior,
},
}

View File

@ -262,7 +262,10 @@ impl Body {
_ => 4.6,
},
Body::Golem(_) => 5.0,
Body::Object(_) => 1.0,
Body::Object(object) => match object {
object::Body::Crossbow => 1.7,
_ => 1.0,
},
}
}

View File

@ -227,6 +227,7 @@ impl LoadoutBuilder {
));
},
},
#[allow(clippy::collapsible_match)] // to be removed when more entries are added
Body::Object(object) => match object {
object::Body::Crossbow => {
main_tool = Some(Item::new_from_asset_expect(

View File

@ -10,7 +10,6 @@ use crate::{
utils::*,
},
uid::Uid,
util::Dir,
Damage, DamageSource, GroupTarget,
};
use serde::{Deserialize, Serialize};
@ -46,7 +45,7 @@ pub struct StaticData {
/// Energy drained per
pub energy_drain: u32,
/// Used to dictate how orientation functions in this state
pub orientation_behavior: OrientationBehavior,
pub orientation_behavior: MovementBehavior,
/// What key is used to press ability
pub ability_info: AbilityInfo,
}
@ -69,16 +68,9 @@ impl CharacterBehavior for Data {
let mut update = StateUpdate::from(data);
match self.static_data.orientation_behavior {
OrientationBehavior::Normal => {},
OrientationBehavior::Turret(speed) => {
MovementBehavior::Normal => {},
MovementBehavior::Turret => {
update.ori.0 = data.inputs.look_dir;
/*update.ori.0 = Dir::new(
Quaternion::from_xyzw(update.ori.0.x, update.ori.0.y, update.ori.0.z, 0.0)
.rotated_z(data.dt.0 as f32 * speed)
.into_vec3()
.try_normalized()
.unwrap_or_default(),
);*/
},
}
@ -114,8 +106,8 @@ impl CharacterBehavior for Data {
});
// Gets offsets
let body_offsets = Vec3::new(
(data.body.radius() + 1.0) * data.inputs.look_dir.x,
(data.body.radius() + 1.0) * data.inputs.look_dir.y,
(data.body.radius() + 1.0) * data.ori.0.x,
(data.body.radius() + 1.0) * data.ori.0.y,
data.body.eye_height(),
) * 0.55;
// Build up
@ -245,7 +237,7 @@ impl CharacterBehavior for Data {
}
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum OrientationBehavior {
pub enum MovementBehavior {
Normal,
Turret(f32),
Turret,
}

View File

@ -1,6 +1,6 @@
use crate::ecs::comp::Interpolated;
use common::{
comp::{Ori, Pos, Vel},
comp::{object, Body, Ori, Pos, Vel},
resources::DeltaTime,
};
use specs::{Entities, Join, Read, ReadStorage, System, WriteStorage};
@ -17,20 +17,28 @@ impl<'a> System<'a> for Sys {
ReadStorage<'a, Pos>,
ReadStorage<'a, Ori>,
ReadStorage<'a, Vel>,
ReadStorage<'a, Body>,
WriteStorage<'a, Interpolated>,
);
fn run(
&mut self,
(entities, dt, positions, orientations, velocities, mut interpolated): Self::SystemData,
(entities, dt, positions, orientations, velocities, mut interpolated, bodies): Self::SystemData,
) {
// Update interpolated positions and orientations
for (pos, ori, i, vel) in (&positions, &orientations, &mut interpolated, &velocities).join()
for (pos, ori, i, vel, body) in (
&positions,
&orientations,
&mut interpolated,
&velocities,
&bodies,
)
.join()
{
// Update interpolation values
if i.pos.distance_squared(pos.0) < 64.0 * 64.0 {
i.pos = Lerp::lerp(i.pos, pos.0 + vel.0 * 0.03, 10.0 * dt.0);
i.ori = Ori::slerp(i.ori, *ori, 5.0 * dt.0);
i.pos = Lerp::lerp(i.pos, pos.0 + vel.0 * 0.03, 5.0 * dt.0);
i.ori = Dir::slerp(i.ori, ori.0, base_ori_interp(body) * dt.0);
} else {
i.pos = pos.0;
i.ori = *ori;
@ -72,3 +80,14 @@ impl<'a> System<'a> for Sys {
}
}
}
#[allow(clippy::collapsible_match)]
fn base_ori_interp(body: &Body) -> f32 {
match body {
Body::Object(object) => match object {
object::Body::Crossbow => 100.0,
_ => 10.0,
},
_ => 10.0,
}
}

View File

@ -384,7 +384,7 @@ impl ParticleMgr {
beam.properties.duration,
time + i as f64 / 1000.0,
ParticleMode::HealingBeam,
pos.0 + *ori.0 * 0.5,
pos.0,
pos.0 + *ori.0 * range,
));
}
@ -400,18 +400,12 @@ impl ParticleMgr {
));
self.particles.resize_with(
self.particles.len()
+ 2 * usize::from(
self.scheduler.heartbeats(Duration::from_millis(1)),
),
+ 2 * usize::from(self.scheduler.heartbeats(Duration::from_millis(1))),
|| {
let phi: f32 =
rng.gen_range(0.0, beam.properties.angle.to_radians());
let phi: f32 = rng.gen_range(0.0, beam.properties.angle.to_radians());
let theta: f32 = rng.gen_range(0.0, 2.0 * PI);
let offset_z = Vec3::new(
phi.sin() * theta.cos(),
phi.sin() * theta.sin(),
phi.cos(),
);
let offset_z =
Vec3::new(phi.sin() * theta.cos(), phi.sin() * theta.sin(), phi.cos());
let random_ori = offset_z * m * Vec3::new(-1.0, -1.0, 1.0);
Particle::new_beam(
beam.properties.duration,