mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Transitioned forced movement to an enum.
This commit is contained in:
parent
981eee5936
commit
1a8cf33a60
@ -337,7 +337,7 @@ impl Tool {
|
|||||||
buildup_duration: Duration::from_millis(200),
|
buildup_duration: Duration::from_millis(200),
|
||||||
shoot_duration: Duration::from_millis(200),
|
shoot_duration: Duration::from_millis(200),
|
||||||
recover_duration: Duration::from_millis(800),
|
recover_duration: Duration::from_millis(800),
|
||||||
leap: Some(10.0),
|
leap: Some(5.0),
|
||||||
projectile: Projectile {
|
projectile: Projectile {
|
||||||
hit_solid: vec![projectile::Effect::Stick],
|
hit_solid: vec![projectile::Effect::Stick],
|
||||||
hit_entity: vec![
|
hit_entity: vec![
|
||||||
|
@ -146,11 +146,13 @@ impl CharacterBehavior for Data {
|
|||||||
StageSection::Swing => {
|
StageSection::Swing => {
|
||||||
if self.timer < self.static_data.stage_data[stage_index].base_swing_duration {
|
if self.timer < self.static_data.stage_data[stage_index].base_swing_duration {
|
||||||
// Forward movement
|
// Forward movement
|
||||||
forward_move(
|
handle_forced_movement(
|
||||||
data,
|
data,
|
||||||
&mut update,
|
&mut update,
|
||||||
|
ForcedMovement::Forward {
|
||||||
|
strength: self.static_data.stage_data[stage_index].forward_movement,
|
||||||
|
},
|
||||||
0.3,
|
0.3,
|
||||||
self.static_data.stage_data[stage_index].forward_movement,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Swings
|
// Swings
|
||||||
|
@ -111,7 +111,14 @@ impl CharacterBehavior for Data {
|
|||||||
&& update.energy.current() > 0
|
&& update.energy.current() > 0
|
||||||
{
|
{
|
||||||
// Forward movement
|
// Forward movement
|
||||||
forward_move(data, &mut update, 0.1, self.static_data.forward_speed);
|
handle_forced_movement(
|
||||||
|
data,
|
||||||
|
&mut update,
|
||||||
|
ForcedMovement::Forward {
|
||||||
|
strength: self.static_data.forward_speed,
|
||||||
|
},
|
||||||
|
0.1,
|
||||||
|
);
|
||||||
|
|
||||||
// This logic basically just decides if a charge should end, and prevents the
|
// This logic basically just decides if a charge should end, and prevents the
|
||||||
// character state spamming attacks while checking if it has hit something
|
// character state spamming attacks while checking if it has hit something
|
||||||
|
@ -6,7 +6,6 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use vek::Vec3;
|
|
||||||
|
|
||||||
/// Separated out to condense update portions of character state
|
/// Separated out to condense update portions of character state
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
@ -76,28 +75,20 @@ impl CharacterBehavior for Data {
|
|||||||
},
|
},
|
||||||
StageSection::Movement => {
|
StageSection::Movement => {
|
||||||
if self.timer < self.static_data.movement_duration {
|
if self.timer < self.static_data.movement_duration {
|
||||||
// Apply jumping force while in Movement portion of state
|
// Apply jumping force
|
||||||
update.vel.0 = Vec3::new(
|
let progress = 1.0
|
||||||
data.inputs.look_dir.x,
|
- self.timer.as_secs_f32()
|
||||||
data.inputs.look_dir.y,
|
/ self.static_data.movement_duration.as_secs_f32();
|
||||||
self.static_data.vertical_leap_strength,
|
handle_forced_movement(
|
||||||
) * 2.0
|
data,
|
||||||
// Multiply decreasing amount linearly over time of
|
&mut update,
|
||||||
// movement duration
|
ForcedMovement::Leap {
|
||||||
* (1.0
|
vertical: self.static_data.vertical_leap_strength,
|
||||||
- self.timer.as_secs_f32()
|
forward: self.static_data.forward_leap_strength,
|
||||||
/ self.static_data.movement_duration.as_secs_f32())
|
progress,
|
||||||
// Apply inputted movement directions at 0.25 strength
|
},
|
||||||
+ (update.vel.0 * Vec3::new(2.0, 2.0, 0.0)
|
0.15,
|
||||||
+ 0.25 * data.inputs.move_dir.try_normalized().unwrap_or_default())
|
);
|
||||||
.try_normalized()
|
|
||||||
.unwrap_or_default()
|
|
||||||
// Multiply by forward leap strength
|
|
||||||
* self.static_data.forward_leap_strength
|
|
||||||
// Control forward movement based on look direction.
|
|
||||||
// This allows players to stop moving forward when they
|
|
||||||
// look downward at target
|
|
||||||
* (1.0 - data.inputs.look_dir.z.abs());
|
|
||||||
|
|
||||||
// Increment duration
|
// Increment duration
|
||||||
// If we were to set a timeout for state, this would be
|
// If we were to set a timeout for state, this would be
|
||||||
|
@ -54,13 +54,18 @@ impl CharacterBehavior for Data {
|
|||||||
StageSection::Movement => {
|
StageSection::Movement => {
|
||||||
// Jumping
|
// Jumping
|
||||||
if let Some(leap_strength) = self.static_data.leap {
|
if let Some(leap_strength) = self.static_data.leap {
|
||||||
update.vel.0 = Vec3::new(
|
let progress = 1.0
|
||||||
data.vel.0.x,
|
- self.timer.as_secs_f32()
|
||||||
data.vel.0.y,
|
/ self.static_data.movement_duration.as_secs_f32();
|
||||||
leap_strength
|
handle_forced_movement(
|
||||||
* (1.0
|
data,
|
||||||
- self.timer.as_secs_f32()
|
&mut update,
|
||||||
/ self.static_data.movement_duration.as_secs_f32()),
|
ForcedMovement::Leap {
|
||||||
|
vertical: leap_strength,
|
||||||
|
forward: 10.0,
|
||||||
|
progress,
|
||||||
|
},
|
||||||
|
1.0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if self.timer < self.static_data.movement_duration {
|
if self.timer < self.static_data.movement_duration {
|
||||||
@ -87,7 +92,12 @@ impl CharacterBehavior for Data {
|
|||||||
StageSection::Buildup => {
|
StageSection::Buildup => {
|
||||||
// Aim gliding
|
// Aim gliding
|
||||||
if self.static_data.leap.is_some() {
|
if self.static_data.leap.is_some() {
|
||||||
update.vel.0 = Vec3::new(data.vel.0.x, data.vel.0.y, 0.0);
|
handle_forced_movement(
|
||||||
|
data,
|
||||||
|
&mut update,
|
||||||
|
ForcedMovement::Hover { move_input: 0.1 },
|
||||||
|
1.0,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if self.timer < self.static_data.buildup_duration {
|
if self.timer < self.static_data.buildup_duration {
|
||||||
// Buildup to attack
|
// Buildup to attack
|
||||||
|
@ -123,7 +123,14 @@ impl CharacterBehavior for Data {
|
|||||||
});
|
});
|
||||||
} else if self.timer < self.static_data.swing_duration {
|
} else if self.timer < self.static_data.swing_duration {
|
||||||
if !self.static_data.is_helicopter {
|
if !self.static_data.is_helicopter {
|
||||||
forward_move(data, &mut update, 0.1, self.static_data.forward_speed);
|
handle_forced_movement(
|
||||||
|
data,
|
||||||
|
&mut update,
|
||||||
|
ForcedMovement::Forward {
|
||||||
|
strength: self.static_data.forward_speed,
|
||||||
|
},
|
||||||
|
0.1,
|
||||||
|
);
|
||||||
handle_orientation(data, &mut update, 1.0);
|
handle_orientation(data, &mut update, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,18 +91,54 @@ fn basic_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
|
|||||||
handle_orientation(data, update, data.body.base_ori_rate());
|
handle_orientation(data, update, data.body.base_ori_rate());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Similar to basic_move function, but with forced forward movement
|
/// Handles forced movement
|
||||||
pub fn forward_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32, forward: f32) {
|
pub fn handle_forced_movement(
|
||||||
let accel = if data.physics.on_ground {
|
data: &JoinData,
|
||||||
data.body.base_accel()
|
update: &mut StateUpdate,
|
||||||
} else {
|
movement: ForcedMovement,
|
||||||
BASE_HUMANOID_AIR_ACCEL
|
efficiency: f32,
|
||||||
};
|
) {
|
||||||
|
match movement {
|
||||||
update.vel.0 += Vec2::broadcast(data.dt.0)
|
ForcedMovement::Forward { strength } => {
|
||||||
* accel
|
let accel = if data.physics.on_ground {
|
||||||
* (data.inputs.move_dir * efficiency + (*update.ori.0).xy() * forward);
|
data.body.base_accel()
|
||||||
|
} else {
|
||||||
|
BASE_HUMANOID_AIR_ACCEL
|
||||||
|
};
|
||||||
|
|
||||||
|
update.vel.0 += Vec2::broadcast(data.dt.0)
|
||||||
|
* accel
|
||||||
|
* (data.inputs.move_dir * efficiency + (*update.ori.0).xy() * strength);
|
||||||
|
},
|
||||||
|
ForcedMovement::Leap {
|
||||||
|
vertical,
|
||||||
|
forward,
|
||||||
|
progress,
|
||||||
|
} => {
|
||||||
|
// Apply jumping force
|
||||||
|
update.vel.0 = Vec3::new(
|
||||||
|
data.inputs.look_dir.x,
|
||||||
|
data.inputs.look_dir.y,
|
||||||
|
vertical,
|
||||||
|
)
|
||||||
|
// Multiply decreasing amount linearly over time (with average of 1)
|
||||||
|
* 2.0 * progress
|
||||||
|
// Apply inputted movement directions with some efficiency
|
||||||
|
+ (data.inputs.move_dir.try_normalized().unwrap_or_default() + update.vel.0.xy())
|
||||||
|
.try_normalized()
|
||||||
|
.unwrap_or_default()
|
||||||
|
// Multiply by forward leap strength
|
||||||
|
* forward
|
||||||
|
// Control forward movement based on look direction.
|
||||||
|
// This allows players to stop moving forward when they
|
||||||
|
// look downward at target
|
||||||
|
* (1.0 - data.inputs.look_dir.z.abs());
|
||||||
|
},
|
||||||
|
ForcedMovement::Hover { move_input } => {
|
||||||
|
update.vel.0 = Vec3::new(data.vel.0.x, data.vel.0.y, 0.0)
|
||||||
|
+ move_input * data.inputs.move_dir.try_normalized().unwrap_or_default();
|
||||||
|
},
|
||||||
|
}
|
||||||
handle_orientation(data, update, data.body.base_ori_rate() * efficiency);
|
handle_orientation(data, update, data.body.base_ori_rate() * efficiency);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,3 +425,18 @@ pub enum AbilityKey {
|
|||||||
Skill1,
|
Skill1,
|
||||||
Dodge,
|
Dodge,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
pub enum ForcedMovement {
|
||||||
|
Forward {
|
||||||
|
strength: f32,
|
||||||
|
},
|
||||||
|
Leap {
|
||||||
|
vertical: f32,
|
||||||
|
forward: f32,
|
||||||
|
progress: f32,
|
||||||
|
},
|
||||||
|
Hover {
|
||||||
|
move_input: f32,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user