As of now, my code checks if either the vectors endpoints are between the rectangles y-values and if they are, it does the same for the x-values, however this is not correct, more andvanced math needs to be used because let's say the y-points of the vector is between the box's y-tops and bottom and x is between the x-boundries it the hitbox becomes a square instead of a line like the vector, I need help to get there. The problem is clear when viewing the graphics because I've made several small rectangles that go red if they collide according to my (faulty) code.
Here's my code for the collision in my rectangle class:
if(swordEndY + swordY > y && swordY < y + size || swordY > y && swordY + swordEndY < y + size) { //Fixa denna if((swordX /*+10*/ > x && swordX+ swordEndX /*+ 10*/ < x + size) || (swordX + swordEndX > x && swordX < x + size)){ // Denna funkar touches=true; } else{touches=false;} }
(If touches is set to true the box turns red)
...And its results:
Munin Vector1.jpg
The pictures are not in order and the blue line is the vector and red squares are "hit".
[UPDATE]
Video for better understanding http://<a href="http://youtu.be/uNkI...NkIxzFvn1w</a>