I've been working on some collision detection and i have managed to get it to know when it touches top bottom left or right, but now i need it so it prevents the rectangle to enter the rectangle and i don't really know how.
Input input = gc.getInput();
mouseX = input.getMouseX()-25;
mouseY = input.getMouseY()-25;
position.x = mouseX;
position.y = mouseY;
if(circle.intersects(rectangle)) {
if(position.x > rectangle.getX() & position.y > rectangle.getY()-50 & position.y < rectangle.getY()+100 & input.isMouseButtonDown(input.MOUSE_LEFT_BUTTON)) {
System.out.println("right");
}
if(position.x < rectangle.getX() & position.y > rectangle.getY()-50 & position.y < rectangle.getY()+100 & input.isMouseButtonDown(input.MOUSE_LEFT_BUTTON)) {
System.out.println("left");
}
if(position.y <= rectangle.getY() & input.isMouseButtonDown(input.MOUSE_LEFT_BUTTON)) {
System.out.println("top");
}
if(position.y >= rectangle.getY()+50 & input.isMouseButtonDown(input.MOUSE_LEFT_BUTTON)) {
System.out.println("bot");
}
}
circle.setX(position.x);
circle.setY(position.y);
hope you guys can help me.