Add more components in /body

* Add mass
* Add density
* Add collider.
This one is strange as always, I don't know what's wrong, but debug hitbox
changes only after death. Real one seems to work.
This commit is contained in:
juliancoffee 2022-08-20 16:59:57 +03:00
parent a371aad05e
commit 6319dcfc22
3 changed files with 31 additions and 27 deletions

View File

@ -27,7 +27,7 @@ use specs::{Component, DerefFlaggedStorage};
use strum::Display;
use vek::*;
use super::{BuffKind, Density, Mass};
use super::{BuffKind, Collider, Density, Mass};
make_case_elim!(
body,
@ -567,6 +567,23 @@ impl Body {
}
}
// Body collider
pub fn collider(&self) -> Collider {
if let Body::Ship(ship) = self {
ship.make_collider()
} else {
let (p0, p1, radius) = self.sausage();
Collider::CapsulePrism {
p0,
p1,
radius,
z_min: 0.0,
z_max: self.height(),
}
}
}
// How far away other entities should try to be. Will be added upon the other
// entity's spacing_radius. So an entity with 2.0 and an entity with 3.0 will
// lead to that both entities will try to keep 5.0 units away from each

View File

@ -3715,11 +3715,10 @@ fn handle_body(
) -> CmdResult<()> {
if let Some(npc::NpcBody(_id, mut body)) = parse_cmd_args!(args, npc::NpcBody) {
let body = body();
let ecs = &server.state.ecs();
let mut bodies = ecs.write_storage::<comp::Body>();
if let Some(mut target_body) = bodies.get_mut(target) {
*target_body = body;
}
insert_or_replace_component(server, target, body, "body")?;
insert_or_replace_component(server, target, body.mass(), "mass")?;
insert_or_replace_component(server, target, body.density(), "density")?;
insert_or_replace_component(server, target, body.collider(), "collider")?;
Ok(())
} else {
Err(action.help_string())

View File

@ -241,10 +241,7 @@ impl StateExt for State {
)
.with(body.mass())
.with(body.density())
.with(match body {
comp::Body::Ship(ship) => ship.make_collider(),
_ => capsule(&body),
})
.with(body.collider())
.with(comp::Controller::default())
.with(body)
.with(comp::Energy::new(
@ -275,7 +272,7 @@ impl StateExt for State {
.with(comp::Ori::default())
.with(body.mass())
.with(body.density())
.with(capsule(&body))
.with(body.collider())
.with(body)
}
@ -290,7 +287,7 @@ impl StateExt for State {
.with(item_drop.orientation(&mut thread_rng()))
.with(item_drop.mass())
.with(item_drop.density())
.with(capsule(&body))
.with(body.collider())
.with(body)
}
@ -352,7 +349,7 @@ impl StateExt for State {
if projectile.is_point {
projectile_base = projectile_base.with(comp::Collider::Point)
} else {
projectile_base = projectile_base.with(capsule(&body))
projectile_base = projectile_base.with(body.collider())
}
projectile_base.with(projectile).with(body)
@ -425,7 +422,10 @@ impl StateExt for State {
.with(pos)
.with(comp::Vel(Vec3::zero()))
.with(comp::Ori::default())
.with(capsule(&object.into()))
.with({
let body: comp::Body = object.into();
body.collider()
})
.with(comp::Body::Object(object))
.with(comp::Mass(100.0))
// .with(comp::Sticky)
@ -577,7 +577,7 @@ impl StateExt for State {
// and we call nothing that can delete it in any of the subsequent
// commands, so we can assume that all of these calls succeed,
// justifying ignoring the result of insertion.
self.write_component_ignore_entity_dead(entity, capsule(&body));
self.write_component_ignore_entity_dead(entity, body.collider());
self.write_component_ignore_entity_dead(entity, body);
self.write_component_ignore_entity_dead(entity, body.mass());
self.write_component_ignore_entity_dead(entity, body.density());
@ -1040,15 +1040,3 @@ fn send_to_group(g: &Group, ecs: &specs::World, msg: &comp::ChatMsg) {
}
}
}
fn capsule(body: &comp::Body) -> comp::Collider {
let (p0, p1, radius) = body.sausage();
comp::Collider::CapsulePrism {
p0,
p1,
radius,
z_min: 0.0,
z_max: body.height(),
}
}