Woo! After so many months, I finally figured out how to get the angles I want in WeaponMainDir! It defines the position of a point that the engine gets the vector of from the weapon origin, like so:
o---->o
First o is the weapon origin, defined in the query function of your script. The second is defined by the coordinates of WeaponMainDir. So, to figure out your numbers (still using o's as the two points):
Draw a triangle
Code: Select all
DistanceX OR DistanceY
o _____________
\ |
\ |
\ |
\ | DistanceZ
\ |
\ | <--- This is your desired angle.
\|
o <--- Weapon origin
Ignore the DistanceY for now.
Lets say you want your gun to aim in a forward facing, 12 degree cone. Well, the degrees in MaxAngleDif start at the vector, and go around clockwise (for X/Z, not certain about Y/Z, but I think it is counter-clockwise) from there, so the default value of straight forward, 0 0 1, will aim straight forward and 12 degrees to the unit's right). Looking like so: (0 to 12 degrees)
__
|/
You need to have that vector be 6 degrees to the left so the cone is actually centered on 0: (-6 to 6 degrees)
__
\|/
Now, if you're comfortable with trigonometry, you can look at the big diagram above and see that the distance you need is opposite the angle/ adjacent the angle = TAN(of the angle). Pull out your handy dandy scientific calculator (or change the one in windows to scientific mode) and plug in TAN(6), getting 0.105104.... Now start trying out fractions of X/Z using the "guess then narrow it down" method (thats the first number and last number of the three defined in MaxAngleDif), to try to get them close (3rd or 4th decimal place should be close enough accuracy) to that decimal number.
They have to be whole numbers! (Why? Because I'm not testing it) If your a trig wizz, which I am not, you may have picked the best numbers just by looking at it. You should find 2/19 produces a good value of 0.105264... Check your values by doing arctan(X/Z) (may be tan(superscript)-1 on your calculator, not to be confused with 1/tan, so don't try that if you can't find it). This should give a number very close to your angle, if you went to the 3rd decimal place in accuracy when picking your X/Z, then the value will be about that accurate as well. In our case, arctan(2/19)=6.009006...
Booya!
If you want that 12 degree cone to be centered around 90 degrees left of the unit, you'd take your 6 degree angle, and at it to 90, so you'd do that process on 96 degrees. You'll find tan(96) comes out negative, thats because your Z value is going to be negative. Go ahead and graph it on a piece of paper if you don't see why its negative.
Now, that DistanceY I told you to ignore! Lets look at it now. You work it the same as for DistanceX. Lets just say when working out your numbers for X you were looking top-down at your unit, for Y your looking at the side. If your using X/Z already, you'll have to use that same value in your Y/Z. Well, at least it makes figuring out Y easier, just multiple the value from tan(angle) by Z. Problem is it will probably be a decimal that you can't round without it being horribly inaccurate. If it is (which is very likely), you might try finding your Y/Z values as when you found X/Z, then use "Least Common Denominators" to have equal Z values and still the desired accuracy on X and Y.
Ok, now where should I wiki this?