Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/entity.cc40
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;
}
}
}