• Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at \$59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

### #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?