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 ryananger

I'm using a number of one-way 'up' tiles and I've been looking for a way to have my character pass DOWN through the tile on a keypress (this is a common mechanic in platformers). I've tried a number of different things but nothing I've come up with has worked so far.

Has anyone implemented this before?

1 decade ago by drhayes

It'll look kinda abrupt, by try adding 1 to your character's y position when you want them to pass through the tile. That'll pass them through the top line of the "only up" tile and should drop them down.

Tested it in my game and it works, at least.

1 decade ago by dominic

Another approach would be to overwrite the Player's .handleMovementTrace() method: If the down button is pressed and the trace result reports a slope collision with the normal pointing straight up (i.e. the one way upwards tile) just ignore the collision - otherwise call the parent implementation and resolve as usual.

Untested:
handleMovementTrace: function( res ) {
	if( 
		ig.input.state('down') && // down button held down?
		res.collision.slope && // slope collision?
		res.collision.slope.nx == 0 && // slope is one-way upwards?
		res.collision.slope.ny == -1 // ...
	) {
		// ignore this collision and just update the pos
		// with the current velocity
		this.pos.x += this.vel.x * ig.system.tick;
		this.pos.y += this.vel.y * ig.system.tick;
	}
	else {
		// resolve as usual
		this.parent( res );
	}
}
Page 1 of 1
« first « previous next › last »