Small gap when landing in platform game
Moderator: Coders of Rage
-
- Chaos Rift Cool Newbie
- Posts: 76
- Joined: Sat Apr 03, 2010 5:08 am
- Programming Language of Choice: C++
Small gap when landing in platform game
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
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
http://www.youtube.com/user/StapledAStapleGun#p/a
My current project
My current project
- short
- ES Beta Backer
- Posts: 548
- Joined: Thu Apr 30, 2009 2:22 am
- Current Project: c++, c
- Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
- Programming Language of Choice: c, c++
- Location: Oregon, US
Re: Small gap when landing in platform game
This and related code.If this is confusing i can post a link to a pic to show what I mean.
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
link: https://github.com/bjadamson
Re: Small gap when landing in platform game
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.
-
- Chaos Rift Cool Newbie
- Posts: 76
- Joined: Sat Apr 03, 2010 5:08 am
- Programming Language of Choice: C++
Re: Small gap when landing in platform game
Ok, here is the picture of the problem:
Here is some code...
I hope this *might* clear things up. The tiles are 32x32 and the player is 19x34
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;
}
}
}
http://www.youtube.com/user/StapledAStapleGun#p/a
My current project
My current project
-
- Chaos Rift Cool Newbie
- Posts: 76
- Joined: Sat Apr 03, 2010 5:08 am
- Programming Language of Choice: C++
Re: Small gap when landing in platform game
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.
Of btw, the bounds rect is the player rect.
http://www.youtube.com/user/StapledAStapleGun#p/a
My current project
My current project
Re: Small gap when landing in platform game
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...
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...
-
- Chaos Rift Cool Newbie
- Posts: 76
- Joined: Sat Apr 03, 2010 5:08 am
- Programming Language of Choice: C++
Re: Small gap when landing in platform game
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
http://www.youtube.com/user/StapledAStapleGun#p/a
My current project
My current project
-
- Chaos Rift Cool Newbie
- Posts: 76
- Joined: Sat Apr 03, 2010 5:08 am
- Programming Language of Choice: C++
Re: Small gap when landing in platform game
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"
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"
http://www.youtube.com/user/StapledAStapleGun#p/a
My current project
My current project
Re: Small gap when landing in platform game
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...