0

i have 2 spaceships. both have polygons. (hitbox) spaceships can be rotated. sooo bounds don't work.

my way to find intersects:

  if (hitbox.intersects(enemyHitbox.getBoundsInLocal())){

            for (int i = 0; i < enemy.length; i++) {
                if (hitbox.contains(enemy[i].getX(), enemy[i].getY())) {
                    System.out.println("HIT");
                } else if (enemyHitbox.contains(p1)) {
                    System.out.println("HIT p1");
                } else if (enemyHitbox.contains(p2)) {
                    System.out.println("HIT p2");
                }  else {
                }
            }
        }

but... there is a problems. when real intersect, but vertex not inside polygon (imagine 2 triangles. 1st have angle 0 and 2nd 180. )

Is there any way to fix? Maybe java have some solution for that?

c0der
  • 18,467
  • 6
  • 33
  • 65
  • Welcome to SO. Please post [mcve] which demonstrates the problem – c0der Jun 17 '17 at 06:25
  • @c0der in this part of cod. it's work. but i need know, maybe it have another way to solve? hitbox 2 points. line. ray.enemy hitbox - triangle. – Максим Jun 17 '17 at 09:12
  • I think [mcve] would also be useful for someone trying to offer an alternative – c0der Jun 17 '17 at 09:30
  • @c0der is correct; if this is not a duplicate, please [edit](https://stackoverflow.com/posts/44600846/edit) your question to include a [mcve] that shows your revised approach using `Shape.intersect()`. – trashgod Jun 17 '17 at 10:40

0 Answers0