Page 1 of 1
Small gap when landing in platform game
Posted: Fri May 21, 2010 10:24 pm
by PaperDuckyFTW
Good day to evarywun!!!!!!!
As the title says, I've come across a cedundrum. In the platofrm game I am making, after implimenting tile based collision I implimented gravity and jumping. All three work fine-however when the player lands there is a small gap maybe 2-5 pixels in height, that is under the player. I dont really mind it, but to make the game look completely awesome I was hoping to eliminate this gap. If this is confusing i can post a link to a pic to show what I mean.
If anyone knows why there is this gap, I would be in your online/virtual debt
Thanks for your help and take care
Re: Small gap when landing in platform game
Posted: Fri May 21, 2010 10:27 pm
by short
If this is confusing i can post a link to a pic to show what I mean.
This and related code.
Re: Small gap when landing in platform game
Posted: Fri May 21, 2010 10:50 pm
by Randi
have you checked to make sure the image of the player is towards the bottom of it? or it could be there is extra space on the tile, or I could be wrong altogether.
Re: Small gap when landing in platform game
Posted: Fri May 21, 2010 10:52 pm
by PaperDuckyFTW
Ok, here is the picture of the problem:
Here is some code...
Code: Select all
//TILE COLLISION
bool tile_collision()
{
for( int x = 0; x < 20; x++ )
{
for( int y = 0; y < 20; y++ )
{
if( map1[y][x] == 2 )
{
if( ( bounds.x+bounds.w > x*32 ) && ( bounds.x < x*32+32 ) &&
( bounds.y+bounds.h > y*32-1 ) && ( bounds.y < y*32+32) )
{
return true;
}
}
}
}
return false;
}
Code: Select all
//exerts from the player class
case SDLK_UP: if( can_jump == true ){ jump_power = -20; can_jump = false; }; break;
void Player::update_player()
{
playerYVel = 5;
if( jump_power < 0 )
{
jump_power++;
}
bounds.x += playerXVel;
if( ( bounds.x < 0 ) || ( bounds.x + PLAYER_WIDTH > LEVEL_W ) || tile_collision() )
{
bounds.x -= playerXVel;
}
bounds.y += playerYVel;
bounds.y += jump_power;
if( ( bounds.y < 0 ) || ( bounds.y + PLAYER_HEIGHT > LEVEL_H ) || tile_collision() )
{
bounds.y -= playerYVel;
can_jump = true;
if(jump_power < 0)
{
jump_power = 0;
bounds.y = bounds.y/32*32+32;
}
}
}
I hope this *might* clear things up. The tiles are 32x32 and the player is 19x34
Re: Small gap when landing in platform game
Posted: Fri May 21, 2010 10:54 pm
by PaperDuckyFTW
With the tile collision things, ive played around with the numbers, an example is the: bounds.y+bounds.h > y*32-1
Of btw, the bounds rect is the player rect.
Re: Small gap when landing in platform game
Posted: Sat May 22, 2010 2:36 pm
by XianForce
Uhh, why do you have a yVelocity and jump power, both adding to bounds.y?
I'd say what's happening is something like this:
bounds.y is increased by playerYVel and jump_power.
Then when there's some type of collision, you undo what you did with the playerYVel ONLY... So I'd say that there may be a problem there...
Re: Small gap when landing in platform game
Posted: Sat May 22, 2010 9:40 pm
by PaperDuckyFTW
What ive done is edited the spritesheet so now there is no transparent pixels under the player in case that was the problem. The problem I am having is that the first time it makes contact with the collision tile, there is no gap underneath the player. However when I kump onto a platform for example, there is the gap. But when i jump back onto the first set of collision tiles, there is no gap. It seems that some tiles leave a gap, while some dont leave any. Im completely stumped
Re: Small gap when landing in platform game
Posted: Sat May 22, 2010 11:40 pm
by PaperDuckyFTW
Okay after staring at the screen while I jump onto the different tiles, I have found out that it seems that colliding with the bottom of the tile is what screws it up. However there is still a few tiels that the gap is there even if its the first tile i collide with. Im really confused becuase there are some tiles that have perfect collision, with no small gap and there are tiles that have gaps no matter what tile i previously collided with.
Okay Im about to kill someone because I just changed it so that theres no gravity and i can move up and down much like an RPG. There is still a goddam gap underneath the player and i have absolutely no clue whats up with it. If anyone knows what MIGHT be the problem, if it works i might just cry in joy. Oh and I think my status thing should be changed to "Chaos Rift NOOB"
Re: Small gap when landing in platform game
Posted: Sun May 23, 2010 1:05 pm
by eatcomics
its probably that your collision just needs to stop when the player is closer to the object... like if you're stopping your player from moving when there would be a collision, just make sure he stops closer to the object... or if you're just moving the player back when he hits the object just don't move him back as far...