Before starting the lecture for applying gravity, I’ve tinkered a bit with the concept myself. Now after completing it I’m left puzzled why if the code is structured like this:
if(IsKeyPressed(KEY_SPACE))
{
velocity -= 10;
}
posY += velocity;
//groud check
if (posY >= windowHeigth-height)
{
//rectangle is on the ground
velocity = 0;
}
else
{
velocity +=gravity;
}
The rectangle doesn’t do anything despite having space pressed, but in this scenario:
if (posY >= windowHeigth-height)
{
//rectangle is on the ground
velocity = 0;
}
else
{
velocity +=gravity;
}
//check for jumping
if(IsKeyPressed(KEY_SPACE))
{
velocity -= 10;
}
It does (the rectangle jumping). How does the ground check intervenes with the previous IF statement.