General Category > Game Development

Beam Weapon Collision Detection

(1/2) > >>

Hearteater:
In response to this mantis issues I mentioned using a translation/rotation approach, instead of a line/circle intersection test.  I threw together a quick C# speed test at lunch and I was getting much better results with translation/rotation even with as few as 50 targets.  I realize you guys don't use doubles for this stuff, but just as a proof of concept I've included the speed test and a results screen shot.

Of course if you are already using translation/rotation then nevermind :) .

x4000:
That's a really hefty improvement!  But you're not getting the exact same results, it looks like?  I am not familiar with the translation/rotation test, and don't really follow the premise of the math it uses (I see what it's doing, and why that's faster, but not what that represents in practical terms).

Hearteater:
Basically you translate the attacker and target to the origin (simple subtraction of the attacker's x and y from the target).  The you rotate the target around the origin so that the beam attack is travelling along the x-axis in the positive direction.  You do this by finding the angle of the beam attack from the x-axis, and then rotate in the opposite direction that amount.  This gives the target a new x and y location.  The attacker doesn't move because he's at the origin.  The beam moves, but we don't need to do any math for that because we already know its width and length and those values translate directly to x and y easily.  Effectively you are now testing for intersection with the positive x-axis up to a point equal to the length of the beam.  Just don't forget to account for the target's radius.  See also the attached image.

The mis-matches appear to all be edge-cases.  The 4000 ship, 10k run matched 99.918% the same which is probably good enough that no human would be able to spot the difference.

x4000:
Very clever!  Thanks for taking the time to explain that to me.

What an amazing thing to have code just handed to us like this.  ;D

Hearteater:
When I found this I was going to do it up using FInt instead of doubles, but to really get an accurate speed test I'd need to run it against your actual collision code anyway, so I figured I'd just do a clean proof of concept.  It still may not be better than what you are doing, but it does look promising.  Anyways, I figured you guys were busy enough with AVWW that fiddling with something like this isn't really something you have time for so I wanted to make it as easy as possible for you guys to take advantage of.

Navigation

[0] Message Index

[#] Next page

Go to full version