fix contact damage and test with impaler

This commit is contained in:
Jim 2025-08-26 08:26:59 -04:00
parent 9d397451c4
commit 5460785348
Signed by: jim
GPG key ID: 3236D2F059A7C0AC
6 changed files with 15 additions and 12 deletions

1
Cargo.lock generated
View file

@ -1644,6 +1644,7 @@ dependencies = [
"bevy",
"building",
"combat",
"combat_damagers",
"state",
]

View file

@ -13,12 +13,12 @@
MouseMovementY: [
CameraPanY,
],
KeyCode(Escape): [
TogglePause,
],
MouseButton(Middle): [
CameraOrbitEnable,
],
KeyCode(Escape): [
TogglePause,
],
KeyCode(F1): [
ToggleDebugUI,
],

View file

@ -10,6 +10,7 @@ avian3d = { workspace = true }
state = { path = "../state" }
combat = { path = "../combat" }
building = { path = "../building" }
combat_damagers = { path = "../combat_damagers" }
[lints]
workspace = true

View file

@ -6,6 +6,7 @@ use avian3d::prelude::*;
use bevy::prelude::*;
use building::Building;
use combat::{Defense, Health};
use combat_damagers::ContactDamage;
use state::GameSystemSet;
pub struct BuildingImpalerPlugin;
@ -47,6 +48,7 @@ fn spawn(
transform.clone(),
Health::new(20.0),
Defense::new(5.0),
ContactDamage { amount: 5.0 },
Name::from("Impaler"),
));
}

View file

@ -19,6 +19,7 @@ impl Plugin for CombatDamagersPlugin {
}
#[derive(Component)]
#[require(CollisionEventsEnabled)]
pub struct ContactDamage {
pub amount: f32,
}
@ -29,6 +30,7 @@ fn deal_contact_damage(
mut commands: Commands,
) {
for event in reader.read() {
info!("event recv!");
if let Ok(contact) = query.get(event.0) {
commands.trigger_targets(
Attacked {

View file

@ -10,7 +10,7 @@ use bevy::{
render::camera::Exposure,
};
use building_core::SpawnCore;
use building_impaler::SpawnImpaler;
use building_impaler::{Impaler, SpawnImpaler};
use camera::ControlledCamera;
use combat::{Attacked, Defense, Health};
use state::AppState;
@ -64,16 +64,13 @@ fn setup(
))
.observe(
|trigger: Trigger<Pointer<Click>>,
mut query: Query<&mut LinearVelocity>,
mut commands: Commands| {
if let Ok(mut v) = query.get_mut(trigger.target()) {
target: Single<&GlobalTransform, With<Impaler>>,
mut query: Query<(&GlobalTransform, &mut LinearVelocity)>| {
if let Ok((gtf, mut v)) = query.get_mut(trigger.target()) {
let delta = target.translation() - gtf.translation();
v.y += 5.0;
v.0 += delta;
}
commands.entity(trigger.target()).trigger(Attacked {
attacker: None,
amount: 8.,
..default()
});
},
);
}