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 codesavage

So from reading the documentation, I was under the impression that handleMovementTrace() compared the x and y of an entity and the collision map. In this case the entity is the player, and I'd like to determine which side of the player the collision happens on so that the player's wall jump ability works correctly. Here's my code:

handleMovementTrace: function( res ) {
	if( res.collision.x ) {
		if( ig.input.pressed('up') ) {
			if( res.tile.x < this.pos.x ) {
				this.vel.x = 100;
				this.vel.y = -this.jump;
			}
			else if( res.tile.x > this.pos.x ) {
				this.vel.x = -100;
				this.vel.y = -this.jump;
			}
		}
	}
	this.parent(res);
},

Unfortunately that doesn't work. "res.tile.x" always reports less than the player's x, regardless of which side the colliding tile is on. Is there somewhere else it gets stored so that I can do an easy comparison like this, or am I completely off base here?

1 decade ago by lTyl

                if(res.collision.x && ig.input.pressed('jump')){
                    this.vel.y = -this.jump;
                }

Will give you a very basic wall-jump, and then to determine if the collision happened on the left or right side, you could use .vel I suppose...
                    if( this.vel.x > 0){
                        console.log("Collision to the Right");
                    }else{
                        console.log("Collision to the Left");
                    }
Page 1 of 1
« first « previous next › last »