I'll just add to Omni's thingy:
sqrt() is actually a less-than-fast function. If you're only doing it occasionally then it's not a big deal, but if you're going to do it every single frame, you could probably find better things for those CPU cycles to do.
So, you should just square the distance your checking. In other words:
// Don't use
if(sqrt( (a*a) + (b*b) ) < 10) {
// Use
if((a*a) + (b*b) < 100) {
It'll be faster. You might want to use a
weapon_length variable of some kind if you intend to allow different weapon lengths. In this case, just set weapon_length_sq = weapon_length * weapon_length when you switch the weapon, and check against that.
Pre-computation is where it's at! :D