0
\$\begingroup\$

I have fixed some of the previous problem. The collision when running into a corner(a wall on two sides) however is still not working. When the player runs into a corner he just falls down and out of the map. Not sure what is happening.

manageWallCollision Method:

@Override
public void manageWallCollision(Scene currScene) {
    for(int i = 0; i < currScene.getMapManager().getWalls().size(); i++){
        MapTile currTile = currScene.getMapManager().getWalls().get(i);

        if(currTile.isCollidable()){
            if(this.getBounds().intersects(currTile.getBounds())){
                //down
                if(vy > 0 && y2 > currTile.getY() && y2 < currTile.getY2()&& y < currTile.getY() && y < currTile.getY2() ){
                    setY((currTile.getY() - getHEIGHT()) - 7);
                    break;
                }
                //up
                else if(vy < 0 && y < currTile.getY2() && y > currTile.getY() && y2 > currTile.getY2() && y2 > currTile.getY()){
                    setY(currTile.getY2() + 7);
                    break;
                }
                //right
                else if(vx > 0 && x2 > currTile.getX() && x2 < currTile.getX2() && x < currTile.getX() && x < currTile.getX2() ){
                    setX((currTile.getX() - getHEIGHT()) - 7);
                    break;
                }
                //left
                else if(vx < 0 && x < currTile.getX2() && x > currTile.getX() && x2 > currTile.getX2() && x2 > currTile.getX()){
                    setX(currTile.getX2() + 7);
                    break;
                }
                break;

            }
        }
    }
}

If you need any more code or info just ask. Any help is appreciated.

bump

\$\endgroup\$
1
  • \$\begingroup\$ Could this because because the player lets go of the move key in the middle of the update loop. I am currently checking for input during the update loop and I am not using a key listener \$\endgroup\$
    – jcsavage
    Sep 12 '14 at 2:59
1
\$\begingroup\$

It looks like your character is entering a tile and then you're setting it just outside of it. If that "just outside" part is actually the border then it's still intersecting and will react the next turn as well. Additionally if you don't also reset their velocity when they hit the barrier, they'll bump it again on the next loop.

On a side note: you don't need all of the "this." portions in your code. The way Java scope works you can't get any scope confusion for anything that's not the same name as a passed in parameter.

\$\endgroup\$
3
  • \$\begingroup\$ Ok so updated my code but now for some reason when the player collides with the corner(a wall on two sides) he simply falls out of the map. I know this is a few days later but I have been busy and this was the first time I had time to look at the code \$\endgroup\$
    – jcsavage
    Sep 12 '14 at 2:25
  • \$\begingroup\$ I haven't looked too closely at your update, but it looks like you're just checking for one tile hit, so maybe it sees that he's hitting the side and stopping that, but because it doesn't also check for hitting the bottom he keeps falling. \$\endgroup\$
    – Eben
    Sep 12 '14 at 8:18
  • \$\begingroup\$ That seemed to do it. The collision is still pretty glitchy but it is at least working now. Thanks again for all the help. \$\endgroup\$
    – jcsavage
    Sep 14 '14 at 23:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.