From 50302a954c21d93512fdbfccc23a792e896920e0 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 4 Dec 2014 17:17:06 +0000 Subject: Improved entity nudging. --- src/core/entity.cc | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'src/core') diff --git a/src/core/entity.cc b/src/core/entity.cc index efd6248..0c49a3e 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -851,27 +851,49 @@ void EntityDynamic::nudge(const bool randomize) if (!zone()) { return; } + + const float DELTA = 0.001f; - for (Zone::Content::const_iterator it = zone()->content().begin(); it != zone()->content().end(); it++) { + for (Zone::Content::const_iterator it = zone()->content().begin(); it != zone()->content().end(); ) { + const Entity *other = (*it); - if ((other->type() != Projectile) && (other != this)) { + if ((other->type() != Projectile) && (other != this) && !other->serverside() && !other->has_flag(Entity::NonSolid) ) + { // check distance const float d = math::distance(location(), other->location()); const float r = radius() + other->radius(); - - if ( d < r ) { - if (randomize) { + + if ( d < r ) + { + if (!randomize) { + // nudge forward + set_location(location() + axis().forward() * r); + + } else if (d < DELTA) { // nudge into randomize direction math::Axis nudge_axis(axis()); - nudge_axis.change_direction(math::randomf(60.0f) - 30.0f); - nudge_axis.change_pitch(math::randomf(60.0f) - 30.0f); - set_location(location() + nudge_axis.forward() * (r - d + 0.001f)); + nudge_axis.change_direction(math::randomf(360.0f)); + nudge_axis.change_pitch(math::randomf(180.0f) - 90.0f); + + set_location(location() + nudge_axis.forward() * r); + } else { - set_location(location() + axis().forward() * (r - d + 0.001f)); + math::Vector3f direction(location() - other->location()); + direction.normalize(); + + set_location(location() + direction * r); } + // restart search it = zone()->content().begin(); + } else { + // next entity + ++it; } + + } else { + // next entity + ++it; } } } -- cgit v1.2.3