• Create Account

Banner advertising on our site currently available from just \$5!

### #ActualKain5056

Posted 24 September 2013 - 07:43 AM

I'm trying to implement 45 degrees slopes in my platform game, and I came up with the following code:

//position.x, position.y, width and height are the sprite's coordinates and size.

void entity::slope_collision_detection( tile * Tile )
{
if( position.y >= Tile->y + ( tile_size - ( position.x + width - Tile->x ) ) - height )
{
position.y = Tile->y + ( tile_size - ( position.x + width - Tile->x ) ) - height;
}

if( position.y + height <= Tile->y ) position.y = Tile->y - height;
}


This code is for the left-pointing slope, btw.

It works great, but the player sprite jitters just a little bit when it's standing still on the slope.
It's not very noticeable, but it's really annoying.

I have tried many things to get rid of it, like changing the order of the collision, moving and displaying functions, or tinkering with the equations, but nothing seems to work.

Can anyone more experienced point me to what I am doing wrong here?

### #1Kain5056

Posted 24 September 2013 - 07:42 AM

I'm trying to implement 45 degrees slopes in my platform game, and I came up with the following code:

//position.x, position.y, width and height are the sprite's coordinates and size.

void entity::slope_collision_detection( tile * Tile )
{
if( position.y >= Tile->y + ( tile_size - ( position.x + width - Tile->x ) ) - height )
{
position.y = Tile->y + ( tile_size - ( position.x + width - Tile->x ) ) - height;
}

if( position.y + height <= Tile->y ) position.y = Tile->y - height;
}


This code is for the left-pointing slope, btw.

It works great, but the player sprite jitters just a little bit when it's standing still on the slope.
It's not very noticeable, but it's really annoying.

I have tried many things to get rid of it, like changing the order of the collision, moving and displaying functions, or tinkering with the equations, but nothing seems to work.

Can anyone more experienced point me to what I am doing wrong here?