I'm trying to solve a bug in this plugin of pixel movement/diagonal. But without success, I need some help :kaodes:
When I go Up(8) + Right(6) the player turns his direction to the right, but stills go up.
When I go Down(2) + Left(6) the player turns his direction to the left, but stills go down.
When I go Right(6) + Down(2) the player turns his direction to down, but stills go right.
When I go Left(4) + Up(8) the player turns his direction to up, but stills go left.
This is strange because the player can walk into a door that is in front of him while facing right for example.
See a video:
Spoiler
I'm pretty sure that the problem is in this part(besides my tries, I cannot make it to work properly):
code line 321
Code:
// ラジアン方向を8方向に変換
CharacterMover.radToDir8 = function(radian) {
var piDiv8 = Math.PI / 8.0;
return (
radian < piDiv8 * -7.0 ? 4 :
radian < piDiv8 * -5.0 ? 7 :
radian < piDiv8 * -3.0 ? 8 :
radian < piDiv8 * -1.0 ? 9 :
radian < piDiv8 * 1.0 ? 6 :
radian < piDiv8 * 3.0 ? 3 :
radian < piDiv8 * 5.0 ? 2 :
radian < piDiv8 * 7.0 ? 1 :
4
);
};
// 8方向をラジアン方向に変換
CharacterMover.dir8ToRad = function(dir8) {
var x = (dir8 % 3 === 0 ? 1.0 : (dir8 % 3 === 1 ? -1.0 : 0.0));
var y = (dir8 / 3 <= 1 ? 1.0 : (dir8 / 3 > 2 ? -1.0 : 0.0));
return Math.atan2(y, x);
};
// ラジアン方向を4方向に変換
CharacterMover.radToDir4 = function(radian) {
var piDiv4 = Math.PI / 4.0;
return (
radian < piDiv4 * -3.0 ? 4 :
radian < piDiv4 * -1.0 ? 8 :
radian < piDiv4 * 1.0 ? 6 :
radian < piDiv4 * 3.0 ? 2 :
4
);
};
// 4方向をラジアン方向に変換
CharacterMover.dir4ToRad = function(dir4) {
return this.dir8ToRad(dir4);
};
// 8方向を4方向に変換
CharacterMover.dir8ToDir4 = function(dir8, dir4) {
return (
dir8 % 2 === 0 ? dir8 :
dir8 === 7 ? (dir4 === 6 ? 8 : 4) :
dir8 === 9 ? (dir4 === 2 ? 6 : 8) :
dir8 === 3 ? (dir4 === 4 ? 2 : 6) :
dir8 === 1 ? (dir4 === 8 ? 4 : 2) :
2
);
};Thanks!