equal
deleted
inserted
replaced
141 && !world.collides(this->position+shape[2]+Vector(0, 1)) |
141 && !world.collides(this->position+shape[2]+Vector(0, 1)) |
142 && !world.collides(this->position+shape[3]+Vector(0, 1)); |
142 && !world.collides(this->position+shape[3]+Vector(0, 1)); |
143 // If, however, there's a force caused by a bomb, e.g., set it in air. |
143 // If, however, there's a force caused by a bomb, e.g., set it in air. |
144 // Still, we have to be able to separate forces caused by walking attempts |
144 // Still, we have to be able to separate forces caused by walking attempts |
145 // and bombs etc (+0.1 because float comparison can be dangerous) |
145 // and bombs etc (+0.1 because float comparison can be dangerous) |
146 if (total.y < 0 || abs(total.x) > PLAYER_MOVE_FORCE + 0.1) |
146 if (total.y < 0.01 || abs(total.x) > PLAYER_MOVE_FORCE + 0.1) |
147 this->inAir = true; |
147 this->inAir = true; |
148 } |
148 } |
149 |
149 |
150 if(!possibleLocation(position)) { |
150 if(!possibleLocation(position)) { |
151 //if we are trapped in ground form dirtball or something |
151 //if we are trapped in ground form dirtball or something |
158 if (!this->inAir) { |
158 if (!this->inAir) { |
159 // It walks only if there's some vertical force |
159 // It walks only if there's some vertical force |
160 if (total.x != 0) { |
160 if (total.x != 0) { |
161 walk(dt, total.x > 0); |
161 walk(dt, total.x > 0); |
162 this->velocity = Vector(0,0); |
162 this->velocity = Vector(0,0); |
163 } |
163 } |
|
164 // Now the possible walking has been done so we can return from this function. |
|
165 // In walk inAir could have been set true, but that will be handled in the next tick. |
|
166 return; |
164 } |
167 } |
165 |
168 |
166 if (!possibleLocation(position)) |
169 if (!possibleLocation(position)) |
167 Engine::log(DEBUG, "PhysicsObject.updatePosition") << "impossible location: " << position; |
170 Engine::log(DEBUG, "PhysicsObject.updatePosition") << "impossible location: " << position; |
168 |
171 |
177 bool collided = false; |
180 bool collided = false; |
178 |
181 |
179 const Vector diffVec = newPosition-position; |
182 const Vector diffVec = newPosition-position; |
180 const Vector unitVector = diffVec / diffVec.length(); |
183 const Vector unitVector = diffVec / diffVec.length(); |
181 Vector reached = position; |
184 Vector reached = position; |
|
185 |
|
186 Engine::log(DEBUG, "physics.update_position") << "unitVector=" << unitVector; |
182 |
187 |
183 while ((position-reached).sqrLength() < diffVec.sqrLength()) { |
188 while ((position-reached).sqrLength() < diffVec.sqrLength()) { |
184 reached += unitVector; |
189 reached += unitVector; |
185 // Check if any of the shapes points collide |
190 // Check if any of the shapes points collide |
186 for (uint64_t i = 0; i < shape.size(); i++) { |
191 for (uint64_t i = 0; i < shape.size(); i++) { |