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

Hi there,

I'm having a problem with my character crouching.

Here is my code:
EntityPlayer = ig.Entity.extend({
	
	size: {x: 20, y:49},
	
	maxVel: {x: 100, y: 200},
	friction: {x: 600, y: 0},
	
	type: ig.Entity.TYPE.A, // Player friendly group
	checkAgainst: ig.Entity.TYPE.NONE,
	collides: ig.Entity.COLLIDES.PASSIVE,
	
	animSheet: new ig.AnimationSheet( 'media/ss.PNG', 20, 49),	
	
	
	flip: false,
	accelGround: 600,
	accelAir: 200,
	jump: 300,
	health: 10,
	flip: false,
    crouch:49/2,
    stand:49,
    crouched:false,
    jumping: false,
//Continue...

And the part of crouch is here:
if(ig.input.state('crouch')) {
            this.size.y = this.crouch;
}

I try with input.pressed too, but doesn't work.

When i press "crouch" (down key) the character go down through the floor.

For example:

| <--- Player
_|_ <--- Floor

But afer pess crouch:


_|_
|

I'm thinking that i have to modify the animsheet, but i don't know how to do that. All the option i think give me an error.

Hope someone can help me.

Thknz!

1 decade ago by Jerczu

you need to set offsets. to compensate size change.

1 decade ago by Vertig0

Thkz master, i have to set the position too and now fix details, but with your help i can found the answer. Thkz again.

Heres the code if someone need to know:
if(ig.input.pressed('crouch')) {
            this.size.y = this.crouch;
            this.offset.y = this.crouch;
            this.pos.y = this.pos.y + this.crouch; 
            this.crouched = true;
}

And the, when nothin is pressed, with a validation i know if the player was crouched:


if(this.crouched){
                this.crouched = false;
                this.offset.y = 0;
                this.size.y = this.stand;
                this.pos.y = this.pos.y-this.crouch;
}

this.currentAnim = this.anims.idle
Page 1 of 1
« first « previous next › last »