# Best way to deal with Collision in JavaFX

This question I'ts no exactly a fix for the current game I'm working on, but I am showing it as an example to explain my problem. I just want to know the best way to handle collision in JavaFX.

My problem is that I cant seem to make collision work with javaFX using the .intercept() function. the way I'm doing it is making a Pane that has the image and different overlapping rectangles that make the collision box. then i add this pane to another pane(the game world). then when I try to get the collision boxes that i want to compare and use .intercept() function it doesn't work, they seem to always collide no matter what, I am using .setLayoutX and Y to move my pane(the ship pane) if that matters and yes I am using .getBoundsOnParent()

The only way i have found that kind of works is comparing the panes themselves but that doesn't work since it just tries to compare the fills.

This is my ship:

This is my Collision Box:

Here is colliding by using the whole pane(see it doesn't work)

(i just want to feel like i am helping a game developer)

From my little knowledge in game development i think they are actually intercepting but not appearing as such, you see you have a rectangle ship-in respect to its bounds

  ________________
|               |
|               |
|    ship one   | // your rectangle shaped ship in layout
|               |
|_______________|           //about to collide with another rectangle shaped
________________
|               |
|               |
|  ship two     | // your rectangle shaped ship in layout
|               |
|_______________|
//collision
//same as these two potions
!
__________v______
|          !     |
| ship one !     |
|          !     |
|        __v_____|______
|_______|_______| <- --|<----- //this portion(s) does not exist in your shaped ship
|              |
|              |
| ship two     |
|______________|


Here you can see both rectangles are touching each other, so you have a collision but your shaped ship dont appear that way because they are not rectangles, your blue vertical portion starts at the middle-same goes for the other, if you look at your image carefully you see that they are touching each other but maybe with a 2dip space. so if i am to give one of my ignorant solutions(i am now trying to enter deep into game development hence that vocab) i will say move your objects past their surface area..

EDIT

Also you are using boundsInParent- which is bigger or than local bounds, a boundsInParent leaves extra room for your nodes so they can go through transformation, rotation etc, without having to overlap other nodes, that explains the etxra 2dip space or my theory