Jump to content

Image of the Day

Everything is fine. 

#screenshotsaturday #indiedev #gamedev https://t.co/98BAKUInyo
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net's newsletters to receive the latest updates and exclusive content.


Sign up now

Small jitter on slope tiles.

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 Kain5056   Members   

502
Like
0Likes
Like

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?

Thank you in advance.  smiley.gif


Edited by Kain5056, 24 September 2013 - 07:43 AM.


#2 deftware   Prime Members   

1767
Like
0Likes
Like

Posted 24 September 2013 - 01:27 PM

Try using greater than, and less than for both comparisons, as opposed to greater-than/equals-to and less-than/equals-to.



#3 Kain5056   Members   

502
Like
0Likes
Like

Posted 24 September 2013 - 04:19 PM

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



#4 pizzafan   Members   

1474
Like
0Likes
Like

Posted 25 September 2013 - 03:23 AM

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)


pizzafan.

#5 Kain5056   Members   

502
Like
0Likes
Like

Posted 25 September 2013 - 04:03 AM

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






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.