• Advertisement
Sign in to follow this  

Small jitter on slope tiles.

This topic is 1579 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Thank you in advance.  smiley.gif

Edited by Kain5056

Share this post


Link to post
Share on other sites
Advertisement

I tried it with no luck. I also tried adding and subtracting small values to both and either the if statement and the entity's y position varying from 0.0001 to 1. Did not work, either. sad.png

Share this post


Link to post
Share on other sites

maybe it's your physics calculations that make the jittering ? or do you use round() somewhere ? (if it's the case, you'd better use floor())

 

...or put all your coordinates in double, if your world is very large ? (float isn't that precise with huge numbers)

Share this post


Link to post
Share on other sites

I almost figured it out. smile.png

//position.x, position.y, width and height are the sprite's coordinates and size.
//float time_step = delta_time->asSeconds() * 32.f;

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

I had to add 1 and subtract the time_step variable because it's the exact distance that I use to check for collisions. It's a bit complicated how I do that, but it works great.

 

The sprite still jitters, but only when its y position is exactly inside (not above or below) the top pixel of the slope tile.

But I think I can figure this one out.

 

Thanks for the help. smile.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement