Jump to content
  • Advertisement
Sign in to follow this  
wanboouit

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.

If you intended to correct an error in the post then please contact us.

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 ...
2bc664870c531aabea999040b7f45f94_39932003.picture.jpg

Share this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
smile.png Thank u ! i will try to fix it sad.png 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 ...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!