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 Jerczu

Just for testing I added some sloped tiles in my old game... They do work pretty good but when I reach the peak of the slope and stop entity slides down at constant speed - Any way I can increase the slide speed while sliding down? I'm guessing this has to have something to do with the friction but is it possible to reduce friction on slope?

1 decade ago by Jerczu

EDIT: Nope this isnt a good solution - still require some help with it... I can grab a tile I'm standing on and decide upon the value returned but isnt there something better?

1 decade ago by Jerczu

Ok I found the solution :)

In handleMovementTrace res object has all the answers...

res.collision.slope ,res.collision.slope, based on this (nx,ny,x,y) I can set up different frictions :D AWESOME!!!

1 decade ago by Jerczu

Its even more awesome that there are directional collision tiles!!!! Dominic you rule!!!!

1 decade ago by stahlmanDesign

Did I miss it or is there a sample game using v1.19 slopes, such as an updated Jump N' Run?

1 decade ago by Arantor

There don't seem to be any sample games showing slopes or the directional collision tiles. No doubt that will be remedied in time...

1 decade ago by Montana

the upward arrow collision tiles (im assuming for jumping through from below) tend to have a jerk of the player sprite to push them onto the top of the platform :-(

where as this code (from the forum) works perfectly, are the up arrows supposed to emulate the feature below? if so, how do you make them behave like below:

handleMovementTrace: function( res ) {
    if( res.tile.x == 2 ) {
        // Always ignore collisions with the PLATFORM_TILE
        // on the x axis
        res.collision.x = false;
        res.pos.x = this.pos.x + this.vel.x * ig.system.tick;
    }
        
    if( res.tile.y == 2 && this.vel.y < 0 ) {
        // Ignore collisions with the PLATFORM_TILE
        // on the y axis, if we're moving upwards
        res.collision.y = false;
        res.pos.y = this.pos.y + this.vel.y * ig.system.tick;
    }

1 decade ago by stahlmanDesign

OK I figured it out. If you download the jumpnrun demo separately from the main v1.19 update, jumpnrun has been updated with v1.19, so you easily add slopes to the demo while editing it in the included weltmeister file.

1 decade ago by Jerczu

Hmm I didnt see the demo --- will check in a bit...

Nah there is no demo its regular jumpnrun with 1.19 libs....

1 decade ago by dominic

There's no demo game showing off the slopes yet.

However, the Jump'n'Run example works well with slopes (edit: appart from animations) - just add some slope tiles for the collision layer in Weltmeister and try it.

1 decade ago by Jerczu

I don't know if this is a bug or not but on the full tiles res.collision.slope fires false on slopes it does fire true but it also does on directional tiles which surely aren't slopes so the slope should fire false... Nx and ny vals are 0 while standing on the directional tile.

1 decade ago by dominic

Mhh, Jerczu, you're right. res.collision.slope is a bit of a misnomer. The thing is, directional tiles are implemented the same way as slopes - it's just a slope that's... not sloped ;)

Maybe it should be called res.collision.linedef instead or just report res.collision.x/y for lines that aren't sloped. I'll fix that in the next version!

1 decade ago by SlouchCouch

I've been playing around with slopes, and I'm wondering how to do the opposite as Jerczu. I'm trying to make it so you don't slide down the hill when just standing there.

I've looked at the new res.collision.slope object, but don't think I can use that information to stop the sliding. I've tried making a custom handleMovementTrace for the entity i don't want to slide, but I can't wrap my head around it.

Any ideas?

1 decade ago by Jerczu

Quote from SlouchCouch
I've been playing around with slopes, and I'm wondering how to do the opposite as Jerczu. I'm trying to make it so you don't slide down the hill when just standing there.


I think you can define .slopeStanding at which angles .standing is true and then just zero the velocities if it is standing.

1 decade ago by SlouchCouch

I've done that, but oddly enough even with 0 velocities in x and y in the update cycle (as viewed from the console) the player entity still slides down the slope slowly.

1 decade ago by Jerczu

??? Weird??? It did work very well in my game I'll try to investigate more and let you know if I find anything.

1 decade ago by Jerczu

I did put my vels in handlemovementtrace though

1 decade ago by Jerczu

And I had a test there if on/off slope

1 decade ago by Xander

Any update on preventing the player entity from sliding down the slope? :)

1 decade ago by drailing

tried to increase the friction of you entity if standing on a slope?

handleMovementTrace: function( res ) {
	if(res.collision.slope){
		this.friction = 9000;
	}
}

1 decade ago by cody

I had the same problem when my player would slow down on a slope but not come to a complete stop.

In the entity class I changed the bottom of handleMovementTrace

var stop_slope = false;

if(res.collision.slope){
	if((this.vel.y < 5 && this.vel.y > 0) && ((this.vel.x < 5 && this.vel.x >0) || (this.vel.x > -5 && this.vel.x < 0))){
		this.vel.x = 0;
		this.vel.y = 0;
		stop_slope=true;
	}
}


//original bottom was: 
//   this.pos = res.pos
if(!stop_slope){
	this.pos = res.pos;
}

So far this has been the only working solution I've come up with.

1 decade ago by Xander

Sweet! I will give it a try! Cheers.

1 decade ago by Xander

Your code seems to work, although I had to increase some of the values since I have a higher gravity than the jumpnrun demo (I am guessing). I had to increase the y values to +/-10 and x to +/-15.

Once I had done so, however, once the player came to a stop on the slope, I couldn't walk down the slope any more (since my x velocity is increased through acceleration and the velocity kept getting zeroed out). So I had to do a check that if my player was pressing left or right, and had no velocity, I would set the velocity to 15 to get over that set amount.

Thanks Cody!

1 decade ago by cody

Great. Glad to hear that worked for you.

1 decade ago by erfuller

So I've read 3-4 posts on trying to prevent sliding down slopes, and none of them work for me. The character will ALMOST stop, but he falls super slowly still.

This is driving me nuts, has anyone found a better way?

Increasing values doesn't seem to work for me. With 200 gravity I can set 9999 friction and he still edges down. The only values that sort of work for negative velocity make him looks like hes doing a crazy dance over and over in place as it falls and catches over and over.

1 decade ago by Ant101

@erfuller - I have exactly the same issue. Would love to know if someone has a solution for this...

1 decade ago by Eddie

I have the same issue as well. I'm working on it now, if I come up with a decent solution, I will share it with you guys!

1 decade ago by Eddie

So this is what I came up with (kind of using Cody's idea):
if( res.collision.slope ) {
			var s = res.collision.slope;
			
			if( this.bounciness > 0 ) {
				var proj = this.vel.x * s.nx + this.vel.y * s.ny;
				
				this.vel.x = (this.vel.x - s.nx * proj * 2) * this.bounciness;
				this.vel.y = (this.vel.y - s.ny * proj * 2) * this.bounciness;
			}
			else {
				var angle = Math.atan2( s.x, s.y );
				if( angle > this.slopeStanding.min && angle < this.slopeStanding.max ) {
					this.standing = true;
					this.vel.x = 0;
					this.vel.y = 0;
				}
				else {
					var lengthSquared = s.x * s.x + s.y * s.y;
					var dot = (this.vel.x * s.x + this.vel.y * s.y)/lengthSquared;
					this.vel.x = 0;
					//this.vel.x = s.x * dot;
					//this.vel.y = s.y * dot;
				}
			}

It ALMOST works. I made it so that I walk up my .slopeStanding slopes but get repelled or slide off slopes with a greater angle than what I set .slopeStanding to.
It also makes my character slide down the 45deg slops A LOT slower than it did before.

What I assume this means is that I got the movement to stop when standing on 45deg slopes, but some OTHER part of the handleMovementTrace function is still causing me to slide.

If anyone has any ideas beyond this, I'll gladly accept some help.

1 decade ago by Ash_Blue

Found this thread when trying to find a quick fix to convert sloped tiles into staircases. The trick is you have to treat the staircase as a ladder and add an extra state similar to this.standing (ex. this.stairs) .My code is for a scalable staircase with minimal resistance, but it eliminates what I'm calling slope decay (standing still and falling back slowly).

This solution is way easier to implement than creating a separate slope entity, adding new slope tiles, or hacking the Impact core code. Hope this helps.

                if (res.collision.slope) {
                    var x = this.vel.x;
                }

                this.parent(res);

                if (res.collision.slope) {
                    if (this.accel.x === 0) {
                        this.pos.x = this.last.x;
                        this.pos.y = this.last.y;
                        this.vel.x = 0;
                        this.vel.y = 0;
                    } else {
                        this.vel.x = (this.flip ? -1 : 1) * Math.min(Math.abs(x), 60);
                    }

                    this.timerStairs.reset();
                    this.standing = true;
                    this.stairs = true;
                }

                if (this.timerStairs.delta() > 0) {
                    this.stairs = false;
                }
Page 1 of 1
« first « previous next › last »