Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

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:

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.

1 decade ago by emati

You could try to eliminate fact that offset or size is causing it.

Simply comment
 this.size.y = this.crouch;
 this.offset.y = this.crouch;

if its not size or offset maybe try to use this.pos.y += this.crouch; instead of this.pos.y = this.pos.y + this.crouch;

or use debug tool, see whats happening when u are pressing 'crouch'.

1 decade ago by Vertig0

Not, it doesn't work :/.

I comment the lines and still not working, work fine when i comment the line of the pos.y.. work fine but dont look fine, like flying.

Thknz anyway!

I'm gonna try moving some variables.

1 decade ago by Vertig0

Ok, i can fix that. The problem, how i think, was that the character gets buried, i fix that setting the offset manualy.

1 decade ago by Jerczu

The fastest way for you to solve it is to run the game in debug mode and turn on collision boxes and offset them accordingly when crouched and when running. Check Blog/Docs on how to set up debug mode.

1 decade ago by Vertig0

Thankz master,

Great tip!

1 decade ago by Jerczu

Glad to be of help
Page 1 of 1
« first « previous next › last »