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:
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?
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?