From d4273c590c619337d3ac28b820ab09283a76a1ec Mon Sep 17 00:00:00 2001 From: otis Date: Tue, 26 Jul 2022 19:10:22 -0400 Subject: [PATCH] added small offset to enemies attacks to align them with animations --- src/attack.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/attack.rs b/src/attack.rs index 55d5ad4c..6a36d124 100644 --- a/src/attack.rs +++ b/src/attack.rs @@ -3,7 +3,7 @@ use std::time::Duration; use bevy::{ core::{Time, Timer}, hierarchy::{BuildChildren, Children, DespawnRecursiveExt}, - math::Vec2, + math::{Vec2, Vec3}, prelude::{ default, App, AssetServer, Assets, Bundle, Commands, Component, Entity, EventReader, Handle, Local, Parent, Plugin, Query, Res, Transform, With, Without, @@ -370,21 +370,32 @@ fn player_flop( } fn enemy_attack( - mut query: Query<(Entity, &mut State, &Handle), (With, With)>, + mut query: Query< + (Entity, &mut State, &Facing, &Handle), + (With, With), + >, mut event_reader: EventReader, mut commands: Commands, fighter_assets: Res>, ) { for event in event_reader.iter() { - if let Ok((entity, mut state, fighter_handle)) = query.get_mut(event.0) { + if let Ok((entity, mut state, facing, fighter_handle)) = query.get_mut(event.0) { if *state != State::Attacking { if rand::random() && *state != State::Waiting { state.set(State::Waiting); } else { state.set(State::Attacking); + //TODO: remove this offset in favor of offsets defined in fighter assets + let offset = match facing { + Facing::Left => -24.0, + Facing::Right => 24.0, + }; + let attack_entity = commands - .spawn_bundle(TransformBundle::default()) + .spawn_bundle(TransformBundle::from_transform( + Transform::from_translation(Vec3::new(offset, 0.0, 0.0)), + )) .insert(Sensor(true)) .insert(ActiveEvents::COLLISION_EVENTS) .insert(