+ 1

# Java collusion

Now I have collusion in my 2d java game but I can't make 2 squares dont go each other. If someone has any ideas or code to give me pls don't be shy

1 Answer

0

if (x1 < x2+width2 and x1 > x2) or (x1+width > x2 and x1 < x2+width2) then you have a collision on the x axis. apply the same to the y axis. then of you have a collision on both axis it means you have an actual collision. Drawing a pic on paper might help visualize Sorry for short explanation there isnt much space, hope this helps.