# HG changeset patch # User nireco # Date 1228175478 0 # Node ID 05f1c957e7766e26b5d14429d11a492166615f11 # Parent fe74105c07eae7dfc692feb42099a0f30d7c52d1 nothing really new diff -r fe74105c07ea -r 05f1c957e776 src/proto2/Physics.cc --- a/src/proto2/Physics.cc Mon Dec 01 23:43:05 2008 +0000 +++ b/src/proto2/Physics.cc Mon Dec 01 23:51:18 2008 +0000 @@ -122,6 +122,12 @@ this->inAir = !world.collides(this->position+shape[2]+Vector(0, 1)); } + if(!possibleLocation(position)) { + //if we are trapped in ground form dirtball or something + //we might want to just return and stuff velocity to some value +// return; + } + if (!this->inAir) { if (total.x != 0) this->position = walk(total.x > 0); @@ -146,6 +152,9 @@ // Check if any of the shapes points collide for (uint64_t i = 0; i < shape.size(); i++) { if (world.getType(reached+shape[i]) != EMPTY) { // Collision + if(i == 0) { + Engine::log(DEBUG, "PhysicsObject.updatePosition ") << "i==0 and collision. It should be impossible -> logic error, someone threw us inside gound."; + } if (inAir) { // Engine::log(DEBUG, "Here"); this->bounce(world.getNormal(reached+shape[i], @@ -167,52 +176,11 @@ } - /* - bool collided = false; - - //goes 1 unit forward every step and check if has hit anything - Vector unitVector = (newPosition-position) / (newPosition-position).length(); - - Vector tmpVector = position; - Vector reached = position; - - int steps = (int) (newPosition-position).length() + 2; - - //Engine::log(DEBUG, "physics.update_position") << unitVector-newPosition; - //Vector foo = position+unitVector*steps-newPosition; - //Engine::log(DEBUG, "PhysicsObject.updatePosition") << "Virhe: "<< foo; - - for(int i = 0; i < steps; i++) { - tmpVector += unitVector; - - float minVelocity = 10; - // Check if any of the four corners of the worm collide - for(int sh = 0; sh < 4; sh++) { - if(world.getType(tmpVector+shape[sh]) != EMPTY) { - reached = position + unitVector*(i-1); - collided = true; - this->bounce(world.getNormal(tmpVector+shape[sh], tmpVector-unitVector+shape[sh])); - this->velocity *= 0.4; - if(abs(this->velocity.x) < minVelocity && (abs(this->velocity.y) < minVelocity)) { - this->inAir = false; - this->velocity = Vector(0,0); - } - break; - } - } - if(collided) - break; - } - */ // In case of some float error check the final coordinate if(!collided) { - if(world.getType(newPosition+shape[0]) != EMPTY || (world.getType(newPosition+shape[1]) != EMPTY) - || (world.getType(newPosition+shape[2]) != EMPTY) || (world.getType(newPosition+shape[3]) != EMPTY)) { - - // Engine::log(DEBUG, "physics.update_position") << "didnt hit"; - // There was error, and there is ground - //newPosition = tmpVector; + if(!possibleLocation(newPosition)) { + newPosition = reached; } else { // This means everything was ok, so no need to do anything }