   line-of-sight as a method of collision detection...sort of
  I'm coding a sort of 2D classical warfare battle simulator.The main issue here is spear-wielders.In the below image, th red rectangle is a spearman, the greens are a front rank of swordsmen on the same side of the spearman, the idea being that the the spearmen poke through the gaps between the swordsmen. The blue is an enemy soldier.The spearman should be able to hit the enemy soldier in the left example, but not in the right example.I decided to implement this with a line-of-sight test with a very short range (i.e. the length of the spear).Using a single point on the target's body to test visibility as is widely the case in games doesn't really make sense for this, so I intend to use a method of sending rays through each vertex of every object in relevant range to determine if any part of the target entity is visible.In the below examples just a small selection of rays are drawn, and the ones in bold establish a line-of-sight from the center-front of the spearman to the enemy soldier.So.First off, I want to check with whoever's reading this before I proceed that this solution so far makes sense and there isn't a better way I could be doing this.Second, there's a basic further problem with this. It's still assuming a single 'eye' point on the spearman to do the test from...but point where he holds the base of the spear is inherently not fixed, so ideally the test should be done from every possible point that the spearman's "arms" can reach...which, as far as I can tell, is impossible.  I'm assuming there's no real solution to this problem, but I'd be very grateful for any suggestions for workarounds. Third, this doesn't yet take the thickness of the spear into account. Line-of-sight is all well and good, but if the gap is too narrow, the spear shouldn't be able to fit through - which is definitely a relevant problem given that I'm using continuous coordinates. My current plan for this is to just overlay an oriented rectangle with the dimensions of the spear in the final stage of the test and check that it doesn't intersect any objects besides the owner and the target...but I've been wondering whether there's some method that's eluding me by which I could use this thickness variable to improve the main test.Keep in mind that although all the rectangles in the given examples are axis-aligned, they CAN be arbitrarily oriented, and needn't even be rectangles - they could be any convex polygon. And also keep in mind that execution time is not much of a concern here - as long as a second for each 'world update' (with hundreds or thousands of soldiers - and space paritioning, mind you :P ) could be acceptable.Thank you for your time.   
  your problem is one of occlusion. TO detect if a shape is completely behind another shape. Here's a solution.img1 : the three boxesimg2 : find the left-most plane passing through the left vertex of the source, and the vertices of the occluding volume. img3 : find the right-most plane passing through the right vertex of the source, and the vertices of the occluding volume. img4 : The two clipping plane of your occlusion volume.img5 : the clipping volume for your occlusion.img6 : clip your target box using the clipping volume. See if anything sticks out.to find which vertex is left-most and right-most should be relatively easy. Also, clipping is not entirely necessary, since your volumes are convex (boxes), you just need to find out if one of your target vertex is outside the left-most plane, or the right-most plane.   ;  actually, proper clipping would be necessary, since you have multiple occluders.   