Increase entity vs entity repulsion factor, add check to ensure entities don't collide with themselves, fix possession projectiles not working on entities in the same group

This commit is contained in:
Imbris 2020-09-19 04:47:40 -04:00
parent ca2aad0080
commit 017d4a3c16
4 changed files with 11 additions and 2 deletions

View File

@ -176,6 +176,7 @@ impl Tool {
],
time_left: Duration::from_secs(15),
owner: None,
ignore_group: true,
},
projectile_body: Body::Object(object::Body::Arrow),
projectile_light: None,
@ -274,6 +275,7 @@ impl Tool {
],
time_left: Duration::from_secs(20),
owner: None,
ignore_group: true,
},
projectile_body: Body::Object(object::Body::BoltFire),
projectile_light: Some(LightEmitter {
@ -303,6 +305,7 @@ impl Tool {
],
time_left: Duration::from_secs(20),
owner: None,
ignore_group: true,
},
projectile_body: Body::Object(object::Body::BoltFireBig),
projectile_light: Some(LightEmitter {
@ -350,6 +353,7 @@ impl Tool {
],
time_left: Duration::from_secs(10),
owner: None,
ignore_group: false,
},
projectile_body: Body::Object(object::Body::ArrowSnake),
projectile_light: Some(LightEmitter {

View File

@ -23,6 +23,9 @@ pub struct Projectile {
/// Time left until the projectile will despawn
pub time_left: Duration,
pub owner: Option<Uid>,
/// Whether projectile collides with entities in the same group as its
/// owner
pub ignore_group: bool,
}
impl Component for Projectile {

View File

@ -136,6 +136,7 @@ impl CharacterBehavior for Data {
],
time_left: Duration::from_secs(15),
owner: None,
ignore_group: true,
};
projectile.owner = Some(*data.uid);
update.server_events.push_front(ServerEvent::Shoot {

View File

@ -158,6 +158,7 @@ impl<'a> System<'a> for Sys {
// Group to ignore collisions with
let ignore_group = projectile
.filter(|p| p.ignore_group)
.and_then(|p| p.owner)
.and_then(|uid| uid_allocator.retrieve_entity_internal(uid.into()))
.and_then(|e| groups.get(e));
@ -185,7 +186,7 @@ impl<'a> System<'a> for Sys {
)
.join()
{
if ignore_group.is_some() && ignore_group == group {
if entity == entity_other || (ignore_group.is_some() && ignore_group == group) {
continue;
}
@ -237,7 +238,7 @@ impl<'a> System<'a> for Sys {
}
if diff.magnitude_squared() > 0.0 {
let force = 40.0 * (collision_dist - diff.magnitude()) * mass_other
let force = 400.0 * (collision_dist - diff.magnitude()) * mass_other
/ (mass + mass_other);
vel_delta += Vec3::from(diff.normalized()) * force * step_delta;