-1
\$\begingroup\$

My current collision resolution code gives a sticky feeling:

private void collision(){
    for (int i = 0; i < handler.object.size(); i++) {

        Gameobject tempObject = handler.object.get(i);

        if(tempObject.getId() == ID.Block) {
            if(getBounds().intersects(tempObject.getBounds())) {
                x += velX * -1;
                y += velY * -1;
            }                                                           
        }
    }
}

This stops the object from penetrating into another one when it collides, but it has a side effect: let's say the block is on top and I'm pressing up and right at the same time, it collides but it'll stop the movement completely and I only want it to stop the Y movement in that case.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.