Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
1  
There are dozens of questions on the site about collision detection. Implement one of the standard algorithms, and if you have problems with that ask a specific question about that. This is essentially a "write my code for me" or "debug my code for me". –  Byte56 Oct 11 at 21:32
 
i'm not asking for code or to debug it i'm asking for a way to make it stop moving into the rectangle –  jan vos Oct 12 at 11:49

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.