# Help: Mario can't falling to ground

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

## Recommended Posts

I'm a newbie in Viet Nam ^^ I'm try to make a Mario clone ... But i have a big problems with my Mario ..

When my mario falling after jump , it collision with the brick and still stand in brick. But when i move mario left or right ... it don't fall into ground .... Someone help me ...

void Mario::UpdateMovement()
{
VelocX += AccelX;

if(!onGround)
VelocY += Gravity;
else
VelocY = 0;
if(VelocY > 15)
VelocY = 15;
if(VelocX > 7.0f)
VelocX = 7.0f;
if(VelocX < -7.0f)
VelocX = -7.0f;
if(AccelX == 0)
{
if(VelocX != 0)
{
if(VelocX > 0)
{
VelocX -= 0.2f;
if(VelocX < 0)
{
VelocX = 0;
}
}
else
{
VelocX += 0.2f;
if(VelocX > 0)
{
VelocX = 0;
}
}
}
}
posX += VelocX;
posY += VelocY;
if(posY >510)
{
posY = 510;
VelocY = 0;
}
if(posX < 0)
posX = 0;
}

void Mario::Jump()
{
if(VelocY == 0)
{
onGround = false;
VelocY = -20.0f;
}
}

void Mario::UpdateCollision(vector<Object *> _listCheckCollision)
{

int size = _listCheckCollision.size();
for(int i = 0; i<size; i++)
{
dirColli = isCollision(_listCheckCollision);
if(dirColli != NONE)
{
switch(_listCheckCollision->getIDObj())
{

case BRICK_CAN_BREAK:
if (dirColli == BOTTOM)
{
onGround = true;
VelocY = 0;
posY = _listCheckCollision->getPosY() - heightObj ;
}
else
onGround = false;
break;
}
}

Picture here ...

##### Share on other sites
Probably the easiest way is making sure that each time your game loop runs (each frame), you set[font=monospace] [/font]onGround variable to false, and run the[font=monospace] [/font]UpdateCollision() method, to make sure it correctly updates the onGround each time. This way even if you don't move Mario, but the ground below his feet disappear, he will fall.

##### Share on other sites
Thank u ! i will try to fix it i spend 2 day but can't fix it ... bore...

P/s: Ok.mario has fall.. but i have other bug When it stand in brick ... it can't jumpsmooth.. because

i have a if...else ...

void Mario::Jump()
{
if(VelocY == 0)
{
onGround = false;
VelocY = -20.0f;
}
}

but when it stand in the brick the Velocity Y chang so fast repeat 1.0000 -> 0.0000 -> 1.0000 ...

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013598
×