Skip to content
Snippets Groups Projects
Commit 15a7d6e9 authored by Manuel Herrmann's avatar Manuel Herrmann
Browse files

fixed being stuck sometimes

parent 8a2f9415
No related branches found
No related tags found
No related merge requests found
......@@ -109,25 +109,26 @@ Char.prototype.animate = function() {
};
Char.prototype.physics = function() {
if (this.moveTarget && this.moveTarget.length == 0) return;
if (Vec.equals(this.translation, this.moveTarget[0])) {
this.moveTarget.shift();
return;
}
var v = Vec.add(Vec.flipSign(this.translation), this.moveTarget[0]);
var d = Vec.length(v);
} else {
var stuckFixer = 0;
do {
var v = Vec.add(Vec.flipSign(this.translation), this.moveTarget[0]);
var d = Vec.length(v);
if (d > this.maxSpeed) {
var n = Vec.mul(v, 1/d); // normalized
v = Vec.mul(n, this.maxSpeed);
}
if (d > this.maxSpeed) {
var n = Vec.mul(v, 1 / d); // normalized
v = Vec.mul(n, this.maxSpeed + stuckFixer);
}
stuckFixer += 0.5;
var nextPosition = (d < g_smallValue) ? this.moveTarget[0] : Vec.add(this.translation, v);
var nextPosition = (d < g_smallValue) ? this.moveTarget[0] : Vec.add(this.translation, v);
} while (!this.pathFinder.canWalkOn(nextPosition[0], nextPosition[1]));
if (this.pathFinder.canWalkOn(nextPosition[0], nextPosition[1]))
Vec.assign(this.translation, nextPosition);
else
this.moveTarget.shift();
}
Game.eventHandler.triggerEventOn('walkon', this.translation[0], this.translation[1]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment