← Back to all posts
##### Player will sometimes hover over a platform then become affected by gravity again after passing it?

I have an infinite runner game that acts really weird and just lets you hover past one platform, any idea why?

hotnewtop
MikeJMS8910 (105)

looks like a cool game. I think what you need to do is add more of a velocity and gravity

MikeJMS8910 (105)

@EthanBlesch ok no problem. If that's the answer you needed then you can just mark the question as answered.

mwilki7 (1137)

Your gravity function looks really complicated
is it possible to simplify it a bit?

``````function doGravity()
{
if (player.y + 30 < currentPlat.y && jumping === false)
{
if (player.x + 30 < plat1.x + plat1.w && player.x + 30 > plat1.x && player.y + 30 === plat1.y)
{
jumpsLeft = 2;
}
else if (player.x + 30 < plat2.x + plat1.w && player.x + 30 > plat2.x && player.y + 30 === plat2.y)
{
jumpsLeft = 2;
}
else if(player.x + 30 < plat3.x + plat3.w && player.x + 30 > plat3.x && player.y + 30 === plat3.y)
{
jumpsLeft = 2;
}
else
{
player.y ++;
}
if(player.y + 30 === currentPlat.y)
{
jumpsLeft = 2;
}
}
}``````

You may want to approach it like this:

``````doGravity()
{
make player fall a little bit

if player is touching anything
push them back up
reset jumps back to 2
}``````