now i hope i understand you correctly.
i would do it like this in your loop:
first - Check for collisions - if the player collides with a wall you set a boolean to true that states this fact.
for example "collisionLeft = true" , or "collisionRight = true", also stop the xVel if you collide.
second - apply the gravity and playermovement:
and simply perform checks there, so for example if theres a "collisionLeft", only allow the player to jump right and vice versa.
Also only allow the player to jump (basicly setting a xVel), if he is colliding with a wall, but in the opposite direction.
ive tryed to do some code here for your case:
1 2 3 4 5
| public void movePlayer(){ yVel = xyz; if (collisionLeft && !collisionRight && Gdx.input.isKeyPressed(Keys.D)) { xVel= 15; } if (!collisionLeft && collisionRight && Gdx.input.isKeyPressed(Keys.A)) { xVel= -15; } } |
ofc in order for that to work, you will need to set the collision booleans like ive wrote before and set the xVel to 0 as soon as you collide with a wall.
btw ive wrote that on my phone, so im sure there are some bugs in there, but i think you will understand what i mean.
