[SOLVED] How to make Rectangle not moving after collision

Hi,
How to make Rectangle not moving after collision?
Look at this GIF:

I don’t know how to fix it, my checkCollision() and move():

	@Override
	public void keyPressed(KeyEvent k) {
		int z = k.getKeyCode();
		switch (z) {
		case KeyEvent.VK_LEFT:
			left = true;
game.physic.leftVel = 2;
			break;
		case KeyEvent.VK_RIGHT:
			right = true;
game.physic.rightVel = 2;
			break;
		case KeyEvent.VK_SPACE:

			break;

		default:
			break;
		}

	}

	public void move() {
		if (left) {
			switch (game.currentLevel()) {
			case 1:
				for (int i = 0; i < game.lvl1.getX().length; i++)
					game.lvl1.getX()[i] += game.physic.leftVel;
				break;

			}
		} else if (right) {
			switch (game.currentLevel()) {
			case 1:
				for (int i = 0; i < game.lvl1.getX().length; i++)
					game.lvl1.getX()[i] -= game.physic.rightVel;
				break;
			}
		}
	}

/*
*
*
*/

public void checkCollision() {
		switch (game.currentLevel()) {
		case 1: //level 1
			for (int i = 0; i < game.lvl1.getX().length; i++) { //scroll through all the platforms
				if (game.man.getBounds().intersects(game.lvl1.getBounds(i))) {
					if (game.man.getBounds().getY() < game.lvl1.getBounds(i)
							.getY() && !game.man.isOnGround) {
						// above
						System.out.println("works^");
						break;
					} else if (game.man.getBounds().getY() > game.lvl1
							.getBounds(i).getY() && isJumping) { //when jumping
						// hit below
						System.out.println("worksV");
						break;
					} else if (game.man.getBounds().getX() < game.lvl1
							.getBounds(i).getX() && right) { //move to the right
						right = false;
						game.physic.rightVel = 0;
						System.out.println("works<");
						break;
						// hit left
					} else if (game.man.getBounds().getX() > game.lvl1
							.getBounds(i).getX() && left) { //move to the left
						left = false;
						game.physic.leftVel = 0;
						System.out.println("works>");
						break;
						// Hit was on right
					}

				}else{ //if doesn't intersect
					game.physic.rightVel = 2;
					game.physic.leftVel = 2;
					game.man.isOnGround = false;
				}
			}
		}
	}

Hope you help me :slight_smile:
Thank,
Szinek

Solved