Merge branch 'slipped/combatstuff' into 'master'

combat ori changes

See merge request veloren/veloren!2198
This commit is contained in:
Justin Shipsey 2021-04-26 02:54:44 +00:00
commit b99404749a
21 changed files with 88 additions and 61 deletions

View File

@ -2,7 +2,7 @@ BasicBeam(
buildup_duration: 0.25, buildup_duration: 0.25,
recover_duration: 0.25, recover_duration: 0.25,
beam_duration: 1.0, beam_duration: 1.0,
damage: 50, damage: 35,
tick_rate: 3.0, tick_rate: 3.0,
range: 20.0, range: 20.0,
max_angle: 15.0, max_angle: 15.0,

View File

@ -10,10 +10,10 @@ DashMelee(
angle: 45.0, angle: 45.0,
energy_drain: 0, energy_drain: 0,
forward_speed: 4.0, forward_speed: 4.0,
buildup_duration: 0.25, buildup_duration: 0.6,
charge_duration: 1.2, charge_duration: 1.2,
swing_duration: 0.1, swing_duration: 0.1,
recover_duration: 0.5, recover_duration: 0.9,
charge_through: true, charge_through: true,
is_interruptible: true, is_interruptible: true,
) )

View File

@ -10,7 +10,7 @@ ComboMelee(
range: 3.5, range: 3.5,
angle: 50.0, angle: 50.0,
base_buildup_duration: 0.4, base_buildup_duration: 0.4,
base_swing_duration: 0.06, base_swing_duration: 0.08,
base_recover_duration: 0.5, base_recover_duration: 0.5,
forward_movement: 2.5, forward_movement: 2.5,
), ),
@ -23,9 +23,9 @@ ComboMelee(
knockback: 12.0, knockback: 12.0,
range: 3.5, range: 3.5,
angle: 30.0, angle: 30.0,
base_buildup_duration: 0.5, base_buildup_duration: 0.7,
base_swing_duration: 0.1, base_swing_duration: 0.1,
base_recover_duration: 0.5, base_recover_duration: 0.7,
forward_movement: 2.0, forward_movement: 2.0,
), ),
], ],

View File

@ -49,6 +49,7 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0);
handle_move(data, &mut update, 0.8); handle_move(data, &mut update, 0.8);
handle_jump(data, &mut update, 1.0); handle_jump(data, &mut update, 1.0);

View File

@ -68,6 +68,7 @@ impl CharacterBehavior for Data {
}, },
} }
handle_orientation(data, &mut update, 0.6);
handle_move(data, &mut update, 0.4); handle_move(data, &mut update, 0.4);
handle_jump(data, &mut update, 1.0); handle_jump(data, &mut update, 1.0);

View File

@ -42,6 +42,7 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0);
handle_move(data, &mut update, 0.3); handle_move(data, &mut update, 0.3);
handle_jump(data, &mut update, 1.0); handle_jump(data, &mut update, 1.0);

View File

@ -37,6 +37,8 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0);
match self.stage_section { match self.stage_section {
StageSection::Buildup => { StageSection::Buildup => {
if self.timer < self.static_data.buildup_duration { if self.timer < self.static_data.buildup_duration {

View File

@ -66,6 +66,7 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0);
handle_move(data, &mut update, 0.7); handle_move(data, &mut update, 0.7);
handle_jump(data, &mut update, 1.0); handle_jump(data, &mut update, 1.0);

View File

@ -65,6 +65,7 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0);
handle_move(data, &mut update, self.static_data.move_speed); handle_move(data, &mut update, self.static_data.move_speed);
handle_jump(data, &mut update, 1.0); handle_jump(data, &mut update, 1.0);

View File

@ -119,8 +119,8 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 0.65);
handle_move(data, &mut update, 0.6); handle_move(data, &mut update, 0.6);
handle_orientation(data, &mut update, 0.2);
let stage_index = (self.stage - 1) as usize; let stage_index = (self.stage - 1) as usize;

View File

@ -26,6 +26,7 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0);
handle_move(data, &mut update, 1.0); handle_move(data, &mut update, 1.0);
handle_jump(data, &mut update, 1.0); handle_jump(data, &mut update, 1.0);

View File

@ -52,6 +52,7 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 0.6);
handle_move(data, &mut update, 0.4); handle_move(data, &mut update, 0.4);
handle_jump(data, &mut update, 1.0); handle_jump(data, &mut update, 1.0);

View File

@ -10,6 +10,7 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0);
handle_move(data, &mut update, 1.0); handle_move(data, &mut update, 1.0);
handle_jump(data, &mut update, 1.0); handle_jump(data, &mut update, 1.0);
handle_wield(data, &mut update); handle_wield(data, &mut update);

View File

@ -47,7 +47,7 @@ impl CharacterBehavior for Data {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
// Smooth orientation // Smooth orientation
handle_orientation(data, &mut update, 1.0); handle_orientation(data, &mut update, 1.3);
match self.stage_section { match self.stage_section {
StageSection::Buildup => { StageSection::Buildup => {

View File

@ -59,6 +59,7 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0);
handle_move(data, &mut update, self.static_data.move_efficiency); handle_move(data, &mut update, self.static_data.move_efficiency);
match self.stage_section { match self.stage_section {

View File

@ -10,6 +10,7 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0);
handle_move(data, &mut update, 0.4); handle_move(data, &mut update, 0.4);
handle_jump(data, &mut update, 1.0); handle_jump(data, &mut update, 1.0);
handle_wield(data, &mut update); handle_wield(data, &mut update);

View File

@ -36,6 +36,7 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0);
handle_move(data, &mut update, self.static_data.movement_speed); handle_move(data, &mut update, self.static_data.movement_speed);
match self.stage_section { match self.stage_section {

View File

@ -245,8 +245,6 @@ pub fn handle_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
/// Updates components to move player as if theyre on ground or in air /// Updates components to move player as if theyre on ground or in air
#[allow(clippy::assign_op_pattern)] // TODO: Pending review in #587 #[allow(clippy::assign_op_pattern)] // TODO: Pending review in #587
fn basic_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) { fn basic_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) {
handle_orientation(data, update, 1.0);
let accel = if data.physics.on_ground { let accel = if data.physics.on_ground {
data.body.base_accel() data.body.base_accel()
} else { } else {
@ -271,8 +269,6 @@ pub fn handle_forced_movement(
movement: ForcedMovement, movement: ForcedMovement,
efficiency: f32, efficiency: f32,
) { ) {
handle_orientation(data, update, efficiency);
match movement { match movement {
ForcedMovement::Forward { strength } => { ForcedMovement::Forward { strength } => {
if let Some(accel) = data.physics.on_ground.then_some(data.body.base_accel()) { if let Some(accel) = data.physics.on_ground.then_some(data.body.base_accel()) {
@ -331,8 +327,6 @@ pub fn handle_orientation(data: &JoinData, update: &mut StateUpdate, efficiency:
/// Updates components to move player as if theyre swimming /// Updates components to move player as if theyre swimming
fn swim_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32, submersion: f32) -> bool { fn swim_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32, submersion: f32) -> bool {
if let Some(force) = data.body.swim_thrust() { if let Some(force) = data.body.swim_thrust() {
handle_orientation(data, update, efficiency * 0.2);
let force = efficiency * force; let force = efficiency * force;
let mut water_accel = force / data.mass.0; let mut water_accel = force / data.mass.0;
@ -374,8 +368,6 @@ pub fn fly_move(data: &JoinData, update: &mut StateUpdate, efficiency: f32) -> b
let accel = thrust / data.mass.0; let accel = thrust / data.mass.0;
handle_orientation(data, update, efficiency);
// Elevation control // Elevation control
match data.body { match data.body {
// flappy flappy // flappy flappy

View File

@ -13,6 +13,7 @@ impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate { fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data); let mut update = StateUpdate::from(data);
handle_orientation(data, &mut update, 1.0);
handle_move(&data, &mut update, 1.0); handle_move(&data, &mut update, 1.0);
handle_climb(&data, &mut update); handle_climb(&data, &mut update);
attempt_input(&data, &mut update); attempt_input(&data, &mut update);

View File

@ -1565,6 +1565,11 @@ impl<'a> AgentData<'a> {
}; };
let dist_sqrd = self.pos.0.distance_squared(tgt_pos.0); let dist_sqrd = self.pos.0.distance_squared(tgt_pos.0);
let angle = self
.ori
.look_vec()
.angle_between(tgt_pos.0 - self.pos.0)
.to_degrees();
// FIXME: Retrieve actual projectile speed! // FIXME: Retrieve actual projectile speed!
// We have to assume projectiles are faster than base speed because there are // We have to assume projectiles are faster than base speed because there are
@ -1598,7 +1603,7 @@ impl<'a> AgentData<'a> {
// depending on the distance from the agent to the target // depending on the distance from the agent to the target
match tactic { match tactic {
Tactic::Melee => { Tactic::Melee => {
if dist_sqrd < min_attack_dist.powi(2) { if dist_sqrd < min_attack_dist.powi(2) && angle < 45.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Primary)); .push(ControlAction::basic_input(InputKind::Primary));
@ -1633,7 +1638,7 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::Axe => { Tactic::Axe => {
if dist_sqrd < min_attack_dist.powi(2) { if dist_sqrd < min_attack_dist.powi(2) && angle < 45.0 {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
if agent.action_timer > 6.0 { if agent.action_timer > 6.0 {
controller controller
@ -1688,7 +1693,7 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::Hammer => { Tactic::Hammer => {
if dist_sqrd < min_attack_dist.powi(2) { if dist_sqrd < min_attack_dist.powi(2) && angle < 45.0 {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
if agent.action_timer > 4.0 { if agent.action_timer > 4.0 {
controller controller
@ -1727,7 +1732,7 @@ impl<'a> AgentData<'a> {
..self.traversal_config ..self.traversal_config
}, },
) { ) {
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 45.0 {
controller.inputs.move_dir = controller.inputs.move_dir =
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
if self if self
@ -1762,7 +1767,7 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::Sword => { Tactic::Sword => {
if dist_sqrd < min_attack_dist.powi(2) { if dist_sqrd < min_attack_dist.powi(2) && angle < 45.0 {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
if self if self
.skill_set .skill_set
@ -1796,7 +1801,7 @@ impl<'a> AgentData<'a> {
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) {
controller.inputs.move_dir = controller.inputs.move_dir =
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
if agent.action_timer > 4.0 { if agent.action_timer > 4.0 && angle < 45.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Secondary)); .push(ControlAction::basic_input(InputKind::Secondary));
@ -1853,10 +1858,12 @@ impl<'a> AgentData<'a> {
self.jump_if(controller, bearing.z > 1.5); self.jump_if(controller, bearing.z > 1.5);
controller.inputs.move_z = bearing.z; controller.inputs.move_z = bearing.z;
} }
if angle < 15.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Primary)); .push(ControlAction::basic_input(InputKind::Primary));
} }
}
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) { } else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
if let Some((bearing, speed)) = agent.chaser.chase( if let Some((bearing, speed)) = agent.chaser.chase(
&*terrain, &*terrain,
@ -1868,7 +1875,7 @@ impl<'a> AgentData<'a> {
..self.traversal_config ..self.traversal_config
}, },
) { ) {
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 45.0 {
controller.inputs.move_dir = bearing controller.inputs.move_dir = bearing
.xy() .xy()
.rotated_z(thread_rng().gen_range(0.5..1.57)) .rotated_z(thread_rng().gen_range(0.5..1.57))
@ -1949,7 +1956,7 @@ impl<'a> AgentData<'a> {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Roll)); .push(ControlAction::basic_input(InputKind::Roll));
} else if dist_sqrd < (5.0 * min_attack_dist).powi(2) { } else if dist_sqrd < (5.0 * min_attack_dist).powi(2) && angle < 15.0 {
if agent.action_timer < 1.5 { if agent.action_timer < 1.5 {
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
.xy() .xy()
@ -1996,7 +2003,7 @@ impl<'a> AgentData<'a> {
..self.traversal_config ..self.traversal_config
}, },
) { ) {
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
controller.inputs.move_dir = bearing controller.inputs.move_dir = bearing
.xy() .xy()
.rotated_z(thread_rng().gen_range(-1.57..-0.5)) .rotated_z(thread_rng().gen_range(-1.57..-0.5))
@ -2042,7 +2049,7 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::StoneGolemBoss => { Tactic::StoneGolemBoss => {
if dist_sqrd < min_attack_dist.powi(2) { if dist_sqrd < min_attack_dist.powi(2) && angle < 45.0 {
// 2.0 is temporary correction factor to allow them to melee with their // 2.0 is temporary correction factor to allow them to melee with their
// large hitbox // large hitbox
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
@ -2066,7 +2073,7 @@ impl<'a> AgentData<'a> {
..self.traversal_config ..self.traversal_config
}, },
) { ) {
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 45.0 {
controller.inputs.move_dir = controller.inputs.move_dir =
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed; bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
if agent.action_timer > 5.0 { if agent.action_timer > 5.0 {
@ -2092,7 +2099,8 @@ impl<'a> AgentData<'a> {
radius, radius,
circle_time, circle_time,
} => { } => {
if dist_sqrd < min_attack_dist.powi(2) && thread_rng().gen_bool(0.5) { if dist_sqrd < min_attack_dist.powi(2) && thread_rng().gen_bool(0.5) && angle < 45.0
{
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
controller controller
.actions .actions
@ -2112,7 +2120,7 @@ impl<'a> AgentData<'a> {
.try_normalized() .try_normalized()
.unwrap_or_else(Vec2::unit_y); .unwrap_or_else(Vec2::unit_y);
agent.action_timer += dt.0; agent.action_timer += dt.0;
} else if agent.action_timer < circle_time as f32 + 0.5 { } else if agent.action_timer < circle_time as f32 + 0.5 && angle < 45.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Secondary)); .push(ControlAction::basic_input(InputKind::Secondary));
@ -2124,7 +2132,7 @@ impl<'a> AgentData<'a> {
.try_normalized() .try_normalized()
.unwrap_or_else(Vec2::unit_y); .unwrap_or_else(Vec2::unit_y);
agent.action_timer += dt.0; agent.action_timer += dt.0;
} else if agent.action_timer < 2.0 * circle_time as f32 + 1.0 { } else if agent.action_timer < 2.0 * circle_time as f32 + 1.0 && angle < 45.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Secondary)); .push(ControlAction::basic_input(InputKind::Secondary));
@ -2153,7 +2161,7 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::QuadLowRanged => { Tactic::QuadLowRanged => {
if dist_sqrd < (3.0 * min_attack_dist).powi(2) { if dist_sqrd < (3.0 * min_attack_dist).powi(2) && angle < 45.0 {
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
.xy() .xy()
.try_normalized() .try_normalized()
@ -2172,7 +2180,7 @@ impl<'a> AgentData<'a> {
..self.traversal_config ..self.traversal_config
}, },
) { ) {
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
if agent.action_timer > 5.0 { if agent.action_timer > 5.0 {
agent.action_timer = 0.0; agent.action_timer = 0.0;
} else if agent.action_timer > 2.5 { } else if agent.action_timer > 2.5 {
@ -2211,7 +2219,7 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::TailSlap => { Tactic::TailSlap => {
if dist_sqrd < (1.5 * min_attack_dist).powi(2) { if dist_sqrd < (1.5 * min_attack_dist).powi(2) && angle < 45.0 {
if agent.action_timer > 4.0 { if agent.action_timer > 4.0 {
controller controller
.actions .actions
@ -2254,13 +2262,14 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::QuadLowQuick => { Tactic::QuadLowQuick => {
if dist_sqrd < (1.5 * min_attack_dist).powi(2) { if dist_sqrd < (1.5 * min_attack_dist).powi(2) && angle < 45.0 {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Secondary)); .push(ControlAction::basic_input(InputKind::Secondary));
} else if dist_sqrd < (3.0 * min_attack_dist).powi(2) } else if dist_sqrd < (3.0 * min_attack_dist).powi(2)
&& dist_sqrd > (2.0 * min_attack_dist).powi(2) && dist_sqrd > (2.0 * min_attack_dist).powi(2)
&& angle < 45.0
{ {
controller controller
.actions .actions
@ -2295,12 +2304,12 @@ impl<'a> AgentData<'a> {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
if agent.action_timer > 5.0 { if agent.action_timer > 5.0 {
agent.action_timer = 0.0; agent.action_timer = 0.0;
} else if agent.action_timer > 2.0 { } else if agent.action_timer > 2.0 && angle < 45.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Secondary)); .push(ControlAction::basic_input(InputKind::Secondary));
agent.action_timer += dt.0; agent.action_timer += dt.0;
} else { } else if angle < 45.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Primary)); .push(ControlAction::basic_input(InputKind::Primary));
@ -2327,12 +2336,12 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::QuadMedJump => { Tactic::QuadMedJump => {
if dist_sqrd < (1.5 * min_attack_dist).powi(2) { if dist_sqrd < (1.5 * min_attack_dist).powi(2) && angle < 45.0 {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Secondary)); .push(ControlAction::basic_input(InputKind::Secondary));
} else if dist_sqrd < (5.0 * min_attack_dist).powi(2) { } else if dist_sqrd < (5.0 * min_attack_dist).powi(2) && angle < 15.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Ability(0))); .push(ControlAction::basic_input(InputKind::Ability(0)));
@ -2347,7 +2356,7 @@ impl<'a> AgentData<'a> {
..self.traversal_config ..self.traversal_config
}, },
) { ) {
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Primary)); .push(ControlAction::basic_input(InputKind::Primary));
@ -2365,7 +2374,7 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::QuadMedBasic => { Tactic::QuadMedBasic => {
if dist_sqrd < min_attack_dist.powi(2) { if dist_sqrd < min_attack_dist.powi(2) && angle < 45.0 {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
if agent.action_timer < 2.0 { if agent.action_timer < 2.0 {
controller controller
@ -2401,12 +2410,12 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::Lavadrake | Tactic::QuadLowBeam => { Tactic::Lavadrake | Tactic::QuadLowBeam => {
if dist_sqrd < (2.5 * min_attack_dist).powi(2) { if dist_sqrd < (2.5 * min_attack_dist).powi(2) && angle < 45.0 {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Secondary)); .push(ControlAction::basic_input(InputKind::Secondary));
} else if dist_sqrd < (7.0 * min_attack_dist).powi(2) { } else if dist_sqrd < (7.0 * min_attack_dist).powi(2) && angle < 15.0 {
if agent.action_timer < 2.0 { if agent.action_timer < 2.0 {
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
.xy() .xy()
@ -2417,7 +2426,7 @@ impl<'a> AgentData<'a> {
.actions .actions
.push(ControlAction::basic_input(InputKind::Primary)); .push(ControlAction::basic_input(InputKind::Primary));
agent.action_timer += dt.0; agent.action_timer += dt.0;
} else if agent.action_timer < 4.0 { } else if agent.action_timer < 4.0 && angle < 15.0 {
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0) controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
.xy() .xy()
.rotated_z(-0.47 * PI) .rotated_z(-0.47 * PI)
@ -2427,7 +2436,7 @@ impl<'a> AgentData<'a> {
.actions .actions
.push(ControlAction::basic_input(InputKind::Primary)); .push(ControlAction::basic_input(InputKind::Primary));
agent.action_timer += dt.0; agent.action_timer += dt.0;
} else if agent.action_timer < 6.0 { } else if agent.action_timer < 6.0 && angle < 15.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Ability(0))); .push(ControlAction::basic_input(InputKind::Ability(0)));
@ -2456,7 +2465,7 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::Theropod => { Tactic::Theropod => {
if dist_sqrd < (2.0 * min_attack_dist).powi(2) { if dist_sqrd < (2.0 * min_attack_dist).powi(2) && angle < 45.0 {
controller.inputs.move_dir = Vec2::zero(); controller.inputs.move_dir = Vec2::zero();
controller controller
.actions .actions
@ -2482,7 +2491,7 @@ impl<'a> AgentData<'a> {
} }
}, },
Tactic::Turret => { Tactic::Turret => {
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Primary)); .push(ControlAction::basic_input(InputKind::Primary));
@ -2492,7 +2501,7 @@ impl<'a> AgentData<'a> {
}, },
Tactic::FixedTurret => { Tactic::FixedTurret => {
controller.inputs.look_dir = self.ori.look_dir(); controller.inputs.look_dir = self.ori.look_dir();
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Primary)); .push(ControlAction::basic_input(InputKind::Primary));
@ -2508,7 +2517,7 @@ impl<'a> AgentData<'a> {
.try_normalized() .try_normalized()
.unwrap_or_default(), .unwrap_or_default(),
); );
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) { if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Primary)); .push(ControlAction::basic_input(InputKind::Primary));
@ -2562,7 +2571,7 @@ impl<'a> AgentData<'a> {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Secondary)); .push(ControlAction::basic_input(InputKind::Secondary));
} else if thread_rng().gen_bool(health_fraction.into()) { } else if thread_rng().gen_bool(health_fraction.into()) && angle < 30.0 {
// Else if at high health, use primary // Else if at high health, use primary
controller controller
.actions .actions
@ -2602,6 +2611,7 @@ impl<'a> AgentData<'a> {
// If random chance and can see target // If random chance and can see target
if thread_rng().gen_bool(0.05) if thread_rng().gen_bool(0.05)
&& can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd)
&& angle < 15.0
{ {
// Fireball // Fireball
controller controller
@ -2660,7 +2670,10 @@ impl<'a> AgentData<'a> {
move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0; move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0;
controller.inputs.move_z = move_dir.z - 0.5; controller.inputs.move_z = move_dir.z - 0.5;
// If further than 4 blocks and random chance // If further than 4 blocks and random chance
if thread_rng().gen_bool(0.05) && dist_sqrd > (4.0 * min_attack_dist).powi(2) { if thread_rng().gen_bool(0.05)
&& dist_sqrd > (4.0 * min_attack_dist).powi(2)
&& angle < 15.0
{
// Fireball // Fireball
controller controller
.actions .actions
@ -2668,7 +2681,9 @@ impl<'a> AgentData<'a> {
} }
} }
// If further than 4 blocks and random chance // If further than 4 blocks and random chance
else if thread_rng().gen_bool(0.05) && dist_sqrd > (4.0 * min_attack_dist).powi(2) else if thread_rng().gen_bool(0.05)
&& dist_sqrd > (4.0 * min_attack_dist).powi(2)
&& angle < 15.0
{ {
// Fireball // Fireball
controller controller
@ -2715,7 +2730,7 @@ impl<'a> AgentData<'a> {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Ability(0))); .push(ControlAction::basic_input(InputKind::Ability(0)));
} else { } else if angle < 45.0 {
// Triple strike // Triple strike
controller controller
.actions .actions
@ -2731,6 +2746,7 @@ impl<'a> AgentData<'a> {
if dist_sqrd > 30.0_f32.powi(2) { if dist_sqrd > 30.0_f32.powi(2) {
if thread_rng().gen_bool(0.05) if thread_rng().gen_bool(0.05)
&& can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd)
&& angle < 15.0
{ {
controller controller
.actions .actions
@ -2779,12 +2795,17 @@ impl<'a> AgentData<'a> {
controller.inputs.move_dir = controller.inputs.move_dir =
move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0; move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0;
controller.inputs.move_z = move_dir.z - 0.5; controller.inputs.move_z = move_dir.z - 0.5;
if thread_rng().gen_bool(0.05) && dist_sqrd > (4.0 * min_attack_dist).powi(2) { if thread_rng().gen_bool(0.05)
&& dist_sqrd > (4.0 * min_attack_dist).powi(2)
&& angle < 15.0
{
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Primary)); .push(ControlAction::basic_input(InputKind::Primary));
} }
} else if thread_rng().gen_bool(0.05) && dist_sqrd > (4.0 * min_attack_dist).powi(2) } else if thread_rng().gen_bool(0.05)
&& dist_sqrd > (4.0 * min_attack_dist).powi(2)
&& angle < 15.0
{ {
controller controller
.actions .actions
@ -2816,12 +2837,12 @@ impl<'a> AgentData<'a> {
self.jump_if(controller, bearing.z > 1.5); self.jump_if(controller, bearing.z > 1.5);
controller.inputs.move_z = bearing.z; controller.inputs.move_z = bearing.z;
} }
} else if self.energy.current() > 600 && agent.action_timer < 3.0 { } else if self.energy.current() > 600 && agent.action_timer < 3.0 && angle < 15.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Ability(0))); .push(ControlAction::basic_input(InputKind::Ability(0)));
agent.action_timer += dt.0; agent.action_timer += dt.0;
} else if agent.action_timer < 6.0 { } else if agent.action_timer < 6.0 && angle < 45.0 {
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Secondary)); .push(ControlAction::basic_input(InputKind::Secondary));

View File

@ -233,8 +233,8 @@ impl Animation for SwimAnimation {
next.torso.orientation = Quaternion::rotation_x( next.torso.orientation = Quaternion::rotation_x(
(((1.0 / switch) * PI / 2.0 + avg_vel.z * 0.12).min(1.57) - PI / 2.0) (((1.0 / switch) * PI / 2.0 + avg_vel.z * 0.12).min(1.57) - PI / 2.0)
+ avgspeed * avg_vel.z * -0.003, + avgspeed * avg_vel.z * -0.003,
) * Quaternion::rotation_y(tilt * 8.0) ) * Quaternion::rotation_y(tilt * 2.0)
* Quaternion::rotation_z(tilt * 8.0); * Quaternion::rotation_z(tilt * 3.0);
next.torso.scale = Vec3::one() / 11.0 * s_a.scaler; next.torso.scale = Vec3::one() / 11.0 * s_a.scaler;
match hands { match hands {
(Some(Hands::One), _) => match active_tool_kind { (Some(Hands::One), _) => match active_tool_kind {