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.x + width > Tile->x )
{
if( position.y + height > Tile->y )
{
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?
Thank you in advance.