Fixed projectile solid collisions

This commit is contained in:
Joshua Barretto 2020-04-26 16:16:35 +01:00
parent 58b30c4518
commit bd2093c819
3 changed files with 9 additions and 37 deletions

View File

@ -120,8 +120,7 @@ impl Tool {
prepare_duration: Duration::from_millis(100),
recover_duration: Duration::from_millis(500),
projectile: Projectile {
hit_ground: vec![projectile::Effect::Stick],
hit_wall: vec![projectile::Effect::Stick],
hit_solid: vec![projectile::Effect::Stick],
hit_entity: vec![
projectile::Effect::Damage(HealthChange {
// TODO: This should not be fixed (?)
@ -162,8 +161,7 @@ impl Tool {
prepare_duration: Duration::from_millis(0),
recover_duration: Duration::from_millis(200),
projectile: Projectile {
hit_ground: vec![projectile::Effect::Vanish],
hit_wall: vec![projectile::Effect::Vanish],
hit_solid: vec![projectile::Effect::Vanish],
hit_entity: vec![
projectile::Effect::Damage(HealthChange {
// TODO: This should not be fixed (?)
@ -190,11 +188,7 @@ impl Tool {
prepare_duration: Duration::from_millis(800),
recover_duration: Duration::from_millis(50),
projectile: Projectile {
hit_ground: vec![
projectile::Effect::Explode { power: 1.4 },
projectile::Effect::Vanish,
],
hit_wall: vec![
hit_solid: vec![
projectile::Effect::Explode { power: 1.4 },
projectile::Effect::Vanish,
],
@ -250,8 +244,7 @@ impl Tool {
prepare_duration: Duration::from_millis(0),
recover_duration: Duration::from_millis(300),
projectile: Projectile {
hit_ground: vec![projectile::Effect::Stick],
hit_wall: vec![projectile::Effect::Stick],
hit_solid: vec![projectile::Effect::Stick],
hit_entity: vec![projectile::Effect::Stick, projectile::Effect::Possess],
time_left: Duration::from_secs(10),
owner: None,

View File

@ -17,8 +17,7 @@ pub enum Effect {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Projectile {
// TODO: use SmallVec for these effects
pub hit_ground: Vec<Effect>,
pub hit_wall: Vec<Effect>,
pub hit_solid: Vec<Effect>,
pub hit_entity: Vec<Effect>,
/// Time left until the projectile will despawn
pub time_left: Duration,
@ -29,9 +28,8 @@ impl Projectile {
pub fn set_owner(&mut self, new_owner: Uid) {
self.owner = Some(new_owner);
for e in self
.hit_ground
.hit_solid
.iter_mut()
.chain(self.hit_wall.iter_mut())
.chain(self.hit_entity.iter_mut())
{
if let Effect::Damage(comp::HealthChange {

View File

@ -57,28 +57,9 @@ impl<'a> System<'a> for Sys {
)
.join()
{
// Hit ground
if physics.on_ground {
for effect in projectile.hit_ground.drain(..) {
match effect {
projectile::Effect::Explode { power } => {
server_emitter.emit(ServerEvent::Explosion {
pos: pos.0,
power,
owner: projectile.owner,
})
},
projectile::Effect::Vanish => server_emitter.emit(ServerEvent::Destroy {
entity,
cause: HealthSource::World,
}),
_ => {},
}
}
}
// Hit wall
else if physics.on_wall.is_some() {
for effect in projectile.hit_wall.drain(..) {
// Hit something solid
if physics.on_wall.is_some() || physics.on_ground || physics.on_ceiling {
for effect in projectile.hit_solid.drain(..) {
match effect {
projectile::Effect::Explode { power } => {
server_emitter.emit(ServerEvent::Explosion {