summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/content/entities/entity_bullet_emitter.rs13
-rw-r--r--src/sim/lib/force.rs1
-rw-r--r--src/sim/sim_manager/utils.rs2
3 files changed, 7 insertions, 9 deletions
diff --git a/src/content/entities/entity_bullet_emitter.rs b/src/content/entities/entity_bullet_emitter.rs
index cddb4b3..c014e8c 100644
--- a/src/content/entities/entity_bullet_emitter.rs
+++ b/src/content/entities/entity_bullet_emitter.rs
@@ -25,16 +25,13 @@ impl EntityBehaviour for BulletEmitterEntityBehaviour {
}
if let Some(target) = self.target {
+ let pos = update_ctx.entity_data.transform(ctx).unwrap().0;
+ let dir = (target - pos).normalize();
+
self.shot_timer -= delta_time;
if self.shot_timer <= 0.0 {
- apply_bullet(
- ctx,
- update_ctx.entity_data.transform(ctx).unwrap().0,
- target,
- 1000,
- );
- // self.shot_timer = 0.1;
- update_ctx.deferred_destroy(update_ctx.entity_data.id);
+ apply_bullet(ctx, pos + (dir * 4.0), target, 70);
+ self.shot_timer = 0.1;
}
self.life -= delta_time;
diff --git a/src/sim/lib/force.rs b/src/sim/lib/force.rs
index c6cfaf0..d461589 100644
--- a/src/sim/lib/force.rs
+++ b/src/sim/lib/force.rs
@@ -98,6 +98,7 @@ pub fn apply_explosion(
}
// TODO profile packing entity ID into cells?
+// TODO sink power in a radius around the impact
// might improve performance by a lot if we don't have to raycast for hit entities
pub fn apply_bullet(ctx: &mut SimCtx, from: Vec2, to: Vec2, power: u32) {
let dda = AwDda::new(from, to);
diff --git a/src/sim/sim_manager/utils.rs b/src/sim/sim_manager/utils.rs
index 38f503a..75ef71d 100644
--- a/src/sim/sim_manager/utils.rs
+++ b/src/sim/sim_manager/utils.rs
@@ -145,7 +145,7 @@ pub fn read_back_entities_from_world(
// first check if the entity has been partitioned
let components = compute_components(&ec.cells, ec.size.x, ec.size.y);
if components.len() == 0 {
- panic!("The entity was completely destroyed?")
+ sim.destroy_entity(entity_id);
} else if components.len() == 1 {
// the entity's cells were changed, but not partitioned
puffin::profile_scope!("Recompute collider");