Jump to content

  • Log In with Google      Sign In   
  • Create Account


Kain5056

Member Since 22 Dec 2012
Offline Last Active Apr 18 2014 12:05 PM
-----

Posts I've Made

In Topic: y = mx + b for sloped tiles

05 October 2013 - 04:14 AM

FPS::FPS_control.last_time is my delta time as seconds * 32. I also use it for the entities movement and collision detection, so I only include it here because the sprite jitters on the slope without it I'm not really sure what you mean above.

I'm also planning to add the options to enable Vertical Sync and FPS Lock at 60 FPS in the Options Menu. Does that help?

I don't really want to permanently lock the FPS, though, because I want to always test the performance with a build-n FPS counter.


In Topic: y = mx + b for sloped tiles

05 October 2013 - 03:22 AM

Oh, I figured it out a few days ago, sorry I forgot to post it. wacko.png

bool entity::slope_collision_detection( tile * Tile )
{
    float y1 , y2 , x1 , x2 , m , b , x;
    y1 = Tile->y;
    y2 = Tile->y + tile_size;
    x1 = Tile->x;
    x2 = Tile->x + tile_size;
    m = ( y2 - y1 ) / ( x2 - x1 );

    if( Tile->tile_type == slope_right )
    {
        if( last_position.x + width - collision_box_position.x - FPS::FPS_control.last_time >= Tile->x + tile_size ) return false;
        m *= -1;
    }

    if( Tile->tile_type == slope_left )
    {
        if( last_position.x + collision_box_position.x + 1 + FPS::FPS_control.last_time <= Tile->x ) return false;
    }

    if( last_position.y + height - collision_box_position.y - 1 + FPS::FPS_control.last_time >= Tile->y + tile_size ) return false;

    b = y1 - m * x1;
    x = position.x + collision_box_position.x * m;


    if( position.y + height >= m * x + b + 1 )
    {
        on_ground = true;
        position.y = m * x + b - height + 1 - FPS::FPS_control.last_time;
        return true;
    }
    return true;
}

The additions and subtractions of 1 and FPS::FPS_control.last_time ( = time step ) are added so the sprite does not jitter, and for the slopes to line up perfectly to each other, so the sprite does not jump when traversing multi-tiled slopes. smile.png

The code works perfectly for me. smile.png


In Topic: y = mx + b for sloped tiles

27 September 2013 - 11:03 AM

Even though I graduated more than a decade ago, I'm not really that good at math.

I'm willing to give it a try, though. The most I can lose is some of my time. smile.png

 

Here is what I figured out so far:

 

   float x , y1 , y2 , x1 , x2 , m , b;
    x = position.x + size - collision_box_position.x;
    y1 = Tile->y + tile_size;
    y2 = Tile->y;
    x1 = Tile->x + tile_size;
    x2 = Tile->x;
    m = ( y2 - y1 ) / ( x2 - x1 );
    b = y1 - m * x1;

    if( position.y + size >= m * x + b ) position.y = m * x + b - size;

 

With the above code it works quite nicely, but for some reason it is offset horizontally by the player's size. I tried adding and subtracting it, but it dod not work.


In Topic: Small jitter on slope tiles.

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


In Topic: Small jitter on slope tiles.

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


PARTNERS