Hi, I have a problem that I don't know how to solve.
I am using physics for a platform game.
But the problem is that the character, when he jumps reaches a distance. But when he presses the left or right button, and then jumps, the height of the jump is less and I don't know why this happens.
The code:
function controles_player(player ref as tipoPlayer)
if (GetRawKeyState(K_RIGHT) or GetRawKeyState(K_LEFT))
if (GetRawKeyState(K_RIGHT)) then caminar_player(player, true)
if (GetRawKeyState(K_LEFT)) then caminar_player(player, false)
endif
//saltar con arriba
if (GetRawKeyState(K_UP))
if (colisionabj_player(player)) then SetSpritePhysicsVelocity(player.spr, GetSpritePhysicsVelocityX(player.spr), -VEL_V)
endif
endfunction
function caminar_player(player ref as tipoPlayer, lado as integer) //hace que el jugador se mueva lateralmente
if (lado = DER)
SetSpritePhysicsVelocity(player.spr, VEL_H, GetSpritePhysicsVelocityY(player.spr))
SetSpriteFlip(player.spr, false, false)
else
SetSpritePhysicsVelocity(player.spr, -VEL_H, GetSpritePhysicsVelocityY(player.spr))
SetSpriteFlip(player.spr, true, false)
endif
endfunction
//calcula la colision por el suelo
function colisionabj_player(player ref as tipoPlayer)
xo as integer //valores offset del sprite
yo as integer
xo = GetSpriteXByOffset(player.spr)
yo = GetSpriteYByOffset(player.spr)
player.colabj = false
for i=0 to array_plataformas.length //para cada elemento en el array de plataformas
//verificar si toca alguno como suelo
player.colabj = SpriteRayCastSingle(array_plataformas[i], xo, yo, xo, yo + 33) //32 es mitad de 64 + 1
if (player.colabj) then exit //de ser asi, salir del ciclo
next i
//retornar si hubo colision hacia abajo
endfunction player.colabj
the scene gravity Y is set to deafult in 50.00
I attach the project so that you can try it out.
the single jump is higher than if I hold the left (or right) button and jump at the same time.