1

I am creating a game using java.awt and was wondering how to do advanced collision detection with Areas. In my game each entity has a collider made with an Area. By advanced collision detection, I mean that I do not want a collision between two areas to result in an entity stopping, rather I want the collision to result in the entity sliding across. Entities have double values of magnitude and direction and a Area of their collision shape. The collision shapes should be able to be any shape (not just rectangles or circles). The output of the program should be a vector that when combined with the entity can result in that entity not colliding.

// Basic collision without sliding
public static boolean testCollsion(Area a, Area b) {
        Area c = (Area) a.clone();
        c.intersect(b);
        return !c.isEmpty();
}
// Advanced sliding collision
// Where b is stationary and a should change
public static void collide(Collidable a, Collidable b) {
    Area areaA = new Area(a.getCollider().shape);
    Area areaB = new Area(b.getCollider().shape);
    Area c = (Area) areaA.clone();
    c.intersect(areaB);
    if (!c.isEmpty()) {
        double directionA = a.getDirection();
        double directionB = b.getDirection();
        double magnitudeA = a.getMagnitude();
        double magnitudeB = b.getMagnitude();
        // Calculate collision vector
        double directionC = ?;
        double magnitudeC = ?;
    }
}

After the collision the entity should be moved out of the area of the thing that it hit while preserving its velocity and direction, and allowing it to slide across the area. This should be done by another vector to cancel out the entity's movement towards the collision.

Jimmy
  • 74
  • 5
  • For [example](https://stackoverflow.com/questions/23332096/how-to-detect-if-two-images-collide-in-java/23332186#23332186) and [example](https://stackoverflow.com/questions/20927189/detecting-collision-of-two-sprites-that-can-rotate/20928531#20928531) – MadProgrammer Apr 04 '19 at 01:17
  • I know how to find the area that is intersecting, but I want to know the change in position to cancel the intersection – Jimmy Apr 04 '19 at 01:24
  • it's vector math dude - yu want to "move out" and to "slide across"?? thats two contradictory things so get your things in place!! – gpasch Apr 04 '19 at 18:25

0 Answers0