1 decade ago by sleenee
I have the most weird bug. I have been looking at this with utmost amazement as I cannot find what could be wrong.
I have an NPC that randomly changes course (top-down view so 4 directions possible) and it does so : it goes to the left, the top or down the screen. However it refuses to go to the right, I really have no clue why. I changed the random number that corresponds to moving to the right, I messed around with a few things and in all cases the only thing he doesn’t want to do is walk to the right. I made two different weltmeister maps and tested the movement in both but it makes no difference (to make sure it’s not some weird map bug).
The code for the character movement AI:
It's usefull code, so everyone who needs the same functionality, be free to use it. I just don't get the walking to the right fixed.
if someone knows what might be wrong, be my guest.
Sleenee
I have an NPC that randomly changes course (top-down view so 4 directions possible) and it does so : it goes to the left, the top or down the screen. However it refuses to go to the right, I really have no clue why. I changed the random number that corresponds to moving to the right, I messed around with a few things and in all cases the only thing he doesn’t want to do is walk to the right. I made two different weltmeister maps and tested the movement in both but it makes no difference (to make sure it’s not some weird map bug).
The code for the character movement AI:
charactermovement: function(){ var randomdirection= Math.floor(Math.random()*5)+1; if( randomdirection == 1 ) { this.vel.x = -64; this.vel.y = 0; this.currentAnim = this.anims.walkleft; this.formerpressed = 'left'; } else if( randomdirection == 3 ) { this.vel.x = 64; this.vel.y = 0; this.currentAnim = this.anims.walkright; this.formerpressed = 'right'; } else if( randomdirection == 2 ) { this.vel.y = -64; this.vel.x = 0; this.currentAnim = this.anims.walkup; this.formerpressed = 'up'; } else if( randomdirection == 4 ) { this.vel.y = 64; this.vel.x = 0; this.currentAnim = this.anims.walkdown; this.formerpressed = 'down'; } else { this.vel.y = 0; this.vel.x = 0; if(this.formerpressed == 'left') { this.currentAnim = this.anims.lookleft; } else if (this.formerpressed == 'right') { this.currentAnim = this.anims.lookright; } else if (this.formerpressed == 'up') { this.currentAnim = this.anims.lookup; } else if (this.formerpressed == 'down') { this.currentAnim = this.anims.lookdown; } } },
It's usefull code, so everyone who needs the same functionality, be free to use it. I just don't get the walking to the right fixed.
if someone knows what might be wrong, be my guest.
Sleenee