1 decade ago by Vertig0
I have a problem with my game that I would like to share in case anyone knows how I could fix it. In it, the character moves by itself without the user pressing anything. As it moves along, speed start to increase. That part works smoothly. The problem is when I pressed down to crouch, it fully stops and when I stop pressing down, the character stands and starts to move again.
I think the problem is when I modify the position, to achieve the crouching. I change the offset and the position as required. Here's my code:
The variables are defined in the constructor
The weird thing is that if I add 1 to the position (in fact, even if I add 0.1), the character doesn't stop, but it stands away a couple of cm from the ground. I'm under the impression that the character gets "buried" on the stage and that's why it can't move.
Any help would be greatly appreciated.
I think the problem is when I modify the position, to achieve the crouching. I change the offset and the position as required. Here's my code:
if(ig.input.pressed('crouch') && !this.jumping) { this.size.y = this.crouch; this.offset.y = this.crouch; this.pos.y = this.pos.y + this.crouch; //here's the problema "crouch" value is 14, //if i change this to 13.9 or less, the character don't stop. this.crouched= true; }
The variables are defined in the constructor
flip: false, jump: 150, crouch: 20*0.7, crouched: false, stand: 20, jumping:true,
The weird thing is that if I add 1 to the position (in fact, even if I add 0.1), the character doesn't stop, but it stands away a couple of cm from the ground. I'm under the impression that the character gets "buried" on the stage and that's why it can't move.
Any help would be greatly appreciated.