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 moon

Hello,

This my game : http://www.crabegame.com, i have a small problem with slope. My character can't ascending this slope and i don't want to touch my gravity...

How can I do ?

Thankss

1 decade ago by StuartTresadern

Hi,

Have you looked at this thread http://impactjs.com/forums/help/good-examples-of-slope-collisions-in-impactjs

1 decade ago by moon

i tried to modify the .slopestanding ... it doesn't work

other idea ?

1 decade ago by StuartTresadern

HI,

I check the tile the player is standing on but also (which is probably the issue you are having) I check if the next tile inline with the player is a slope. so in my case I do the following checks:

var currentTile = ig.game.collisionMap.getTile(this.pos.x+this.size.x,this.pos.y+this.size.y +1);

var nextTile = ig.game.collisionMap.getTile(this.pos.x+this.size.x,this.pos.y+this.size.y);

// If I want to check if the slope is going Up to the right,
// in my move code for right I can see if I need to give my player a little help getting up the slope


if ((currentTile>=2 && currentTile <=7) || (nextTile>=2 && nextTile <=7))
{

	this.vel.y -=6 // value depends on your gravity settings etc

}

Give that a try (obviously you need to do the left checks to). you need to play about with the amount of velocity required but between 5 and 10 is normally a good starting point.

Stuart

1 decade ago by moon

Thanks, but i have a last problem

http://crabegame.com/stuart/#.T-m5zrU0Msc

Your example work perfectly from left to right but as u can see in the other way it doesn't work.

On the bottom of the page you can see CurrentTile, NextTile and vel.y... it's stranger when i try to ascend a slop from right to left currentil = 1 and nexttile = 1

Thanks for your help

1 decade ago by StuartTresadern

Ok, you need to put the slope test when you test for the left or right button so you know which set of slope tiles to test against (not after the key tests as your current code).

##

if (ig.input.state('left'))
// here

if (ig.input.state('right'))
// here

##

I do not have impactjs to hand at the moment but if you look in the collision-map.js file under defaultTileDef you will see the tile numbers you need to check against for moving left. (North West).

Also if you need to, based on the slope of the tile (just by using the tile numbers) you can increase / decrease the velocity as required.

Personally I ignore the South West and South East slopes and just let gravity do the work.But of course you could slow down the entity if required.
Page 1 of 1
« first « previous next › last »