That they can't run thought the other Object. ^^
Thx


Actor wall = getOneObjectAtOffset(Wall.class, xOffset, yOffset); //xOffset and yOffset can be whatever you want if(wall == null) { //if the person is not touching a wall move();//or do whatever you do to move the person } //if the wall is not null(it is real and is touching the person), do nothing.
TeamRot redTeamMember = getOneObjectAtOffset(TeamRot.class, xOffset, yOffset); //xOffset and yOffset can be whatever you want Ball ball = getOneObjectAtOffset(Ball.class, xOffset, yOffset); //xOffset and yOffset can be whatever you want if(redTeamMember == null && ball == null) { //if the player is not hitting an opposing team member, or the ball //put the code to move the player here }
TeamRot redTeamMember = getOneObjectAtOffset(TeamRot.class, xOffset, yOffset); //xOffset and yOffset can be whatever you want if(redTeamMember == null) { //if the player is not hitting an opposing team member //then it can catch the ball, tryToCatchBall(); //put the code to move the player here } //here is what tryToCatchBall() should look like: public void tryToCatchBall() { Ball ball = (Ball) getOneIntersectingObject(this); if(ball != null) { //we divide the width and height by 2 to get the space between the center of the player and the edge of the player's image. int width = getImage().getWidth()/2; int height = getImage().getHeight()/2; if(direction.equals("west")) ball.setLocation(getX()-width, getY()); else if(direction.equals("north")) ball.setLocation(getX(), getY()-height); else if(direction.equals("east")) ball.setLocation(getX()+width, getY()); else if(direction.equals("south")) ball.setLocation(getX(), getY()+height); } }