diff options
author | Stijn Buys <ingar@osirion.org> | 2014-12-04 17:17:06 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2014-12-04 17:17:06 +0000 |
commit | 50302a954c21d93512fdbfccc23a792e896920e0 (patch) | |
tree | 97ba49f83c9be7b7c25945cf298298ae529b0234 /src/core | |
parent | 61b3e890750006ff5cae5d8d78f42cd28a620c1d (diff) |
Improved entity nudging.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/entity.cc | 40 |
1 files changed, 31 insertions, 9 deletions
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; } } } |