From: Christoph Sommer Date: Thu, 1 Feb 2007 22:01:35 +0000 (+0000) Subject: Clip object velocity at 16, so objects no longer get stuck in others, e.g. after... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=a4977e73042b36173c9fb6b353ca205b9715f6c2;p=supertux.git Clip object velocity at 16, so objects no longer get stuck in others, e.g. after a long fall SVN-Revision: 4775 --- diff --git a/src/sector.cpp b/src/sector.cpp index 79ad45986..125d18648 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -1184,6 +1184,10 @@ Sector::collision_static_constrains(MovingObject& object) } } +namespace { + const float MAX_SPEED = 16.0f; +} + void Sector::handle_collisions() { @@ -1193,6 +1197,13 @@ Sector::handle_collisions() for(MovingObjects::iterator i = moving_objects.begin(); i != moving_objects.end(); ++i) { MovingObject* moving_object = *i; + Vector mov = moving_object->get_movement(); + + // make sure movement is never faster than MAX_SPEED. Norm is pretty fat, so two addl. checks are done before. + if (((mov.x > MAX_SPEED * M_SQRT1_2) || (mov.y > MAX_SPEED * M_SQRT1_2)) && (mov.norm() > MAX_SPEED)) { + moving_object->movement = mov.unit() * MAX_SPEED; + //log_debug << "Temporarily reduced object's speed of " << mov.norm() << " to " << moving_object->movement.norm() << "." << std::endl; + } moving_object->dest = moving_object->get_bbox(); moving_object->dest.move(moving_object->get_movement());