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 Eddie

I've been following a ton of slope sliding threads because it seems there are a good amount of people out there who are trying to achieve the same result I am.
That result is to NOT slide off slopes.

The main thread I've been following has been this one, but still no one has come up with a definite universal answer.

I've tried several of the approaches, even changing the traceMovement methods still to no avail. Does anyone out there have a definite solution to this?

I'm sure I speak for a lot of Impact devs when I say thank you to anyone who can provide some insight.

1 decade ago by quidmonkey

I can haz cookie?

ig.module(
    'game.entities.player'
)
.requires(
    'impact.entity'
)
.defines(function(){

EntityPlayer = ig.Entity.extend({

	//impact
	animSheet: new ig.AnimationSheet( 'media/player.png', 16, 16 ),
	size: { x: 16, y: 16 },

	//collision
	checkAgainst: ig.Entity.TYPE.B,
	collides: ig.Entity.COLLIDES.ACTIVE,
	type: ig.Entity.TYPE.A,

	//unique
	flip: false,
	jump: 200,
	speed: 30,

	init: function( x, y, settings ){
		this.parent( x, y, settings );
		this.addAnim( 'idle', 1, [0] );
		this.addAnim( 'run', 0.07, [0, 1, 2, 3, 4, 5] );
		this.addAnim( 'jump', 1, [9] );
		this.addAnim( 'fall', 0.4, [6, 7] );
	},

	handleMovementTrace: function( res ){
		this.parent( res );

		//if standing on slope and no key press
		//stop all movement
		if( res.collision.slope && this.standing && this.noKeyPress() ){
			this.pos.x = this.last.x;
			this.pos.y = this.last.y;
			this.vel.x = 0;
			this.vel.y = 0;
		}
	},

	noKeyPress: function(){
		var actions = ig.input.actions;
		for( var action in actions ){
			if( actions[action] ){
				return false;
			}
		}
		var presses = ig.input.presses;
		for( var press in presses ){
			if( presses[press] ){
				return false;
			}
		}
		return true;
	},

	update: function(){
		if( ig.input.state( 'left' ) ){
			this.flip = true;
			this.vel.x = -this.speed;
		}
		else if( ig.input.state( 'right' ) ){
			this.flip = false;
			this.vel.x = this.speed;
		}
		else{
			this.vel.x = 0;
		}

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

		if( this.vel.y < 0 && !this.standing ){
			this.currentAnim = this.anims.jump;
		}
		else if( this.vel.y > 0 && !this.standing ){
			this.currentAnim = this.anims.fall;
		}
		else if( this.vel.x !== 0 ){
			this.currentAnim = this.anims.run;
		}
		else{
			this.currentAnim = this.anims.idle;
		}

		this.currentAnim.flip.x = this.flip;
		this.parent();
	}

});

});

1 decade ago by fugufish

@Eddie are you looking to do something like this? http://marketjs.com/game/emmas-gems . it's built with slopes

1 decade ago by Eddie

/><br />
<br />
^That's my mind right now. Not only did you swiftly and impressively solve my problem, the way you coded it taught me how to define custom functions and how to use an enumerator inside Impact.<br />
<br />
You sir, are brilliant. If this were Stack Overflow, you'd get an up arrow from me.			</div>
		</div>
			<div class=

1 decade ago by Eddie

That being said, there are a couple of bugs, but I'll figure it out as I go :]
The player glitches out when resolving collisions with slopes (weird animation glitches) that sometimes spill over to one way tiles, but still, much appreciated :D

1 decade ago by quidmonkey

Try upping ig.game.gravity by a large margin. Slope collisions add vel that can make your character feel bouncy, even if .bounciness = 1.

1 decade ago by quidmonkey

I removed the this.vel.y = 0 from .handleMovementTrace():
handleMovementTrace: function( res ){
		this.parent( res );

		//if standing on slope and no key press
		//stop all movement
		if( res.collision.slope && this.standing && this.noKeyPress() ){
			this.pos.x = this.last.x;
			this.pos.y = this.last.y;
			this.vel.x = 0;
		}
	},

I then set ig.game.gravity = 800. This allowed me to run up and down hills with minimal bounce. Setting gravity even higher will eliminate bounce altogether.
Page 1 of 1
« first « previous next › last »