Restricted-arc weapons and Spring's aiming code.
Moderator: Moderators
Ok, tested it.
On the one hand, it works very well, in terms of detecting targets. I'd say that that bug is fixed.
On the other hand... well, it's doing something funky still: whenever AimWeaponX() is being invoked (i.e., whenever an enemy enters LOS) restricted-arc weapons are doing this bizarre behavior where they constantly return to 0 on the Y-axis, instead of remaining aimed. This happens every frame or so, and looks quite bad.
This is specific to restricted-arc weapons- non-restricted ones don't show this behavior. It's almost like they are constantly being sent a 0 vector, instead following directions from the BOS, so they first turn due to the BOS, then are told to turn towards 0 Y, then spin further towards the target, etc. It effectively makes units lock up when aiming to the sides of a wide arc.
I've seen this problem since I first messed with restricted-arc weapons, but I got around it by using code like this:
This code basically told the Piece to either spin to the right or the left, depending on the vector to the target.
Well... this code no longer seems to help any. There's something very funky in the way that restricted-arc weapons are being aimed by Spring... it's almost like it's checking to see if they've passed their maximum-allowed angle, along with everything else- and if they have, instead of *stopping* their rotation, which is what they should do, they're attempting to rotate back to 0 Y
This is, obviously, not ideal.
So, I checked through the code...
On the one hand, it works very well, in terms of detecting targets. I'd say that that bug is fixed.
On the other hand... well, it's doing something funky still: whenever AimWeaponX() is being invoked (i.e., whenever an enemy enters LOS) restricted-arc weapons are doing this bizarre behavior where they constantly return to 0 on the Y-axis, instead of remaining aimed. This happens every frame or so, and looks quite bad.
This is specific to restricted-arc weapons- non-restricted ones don't show this behavior. It's almost like they are constantly being sent a 0 vector, instead following directions from the BOS, so they first turn due to the BOS, then are told to turn towards 0 Y, then spin further towards the target, etc. It effectively makes units lock up when aiming to the sides of a wide arc.
I've seen this problem since I first messed with restricted-arc weapons, but I got around it by using code like this:
Code: Select all
heading_01 = heading;
if ( heading_01 <= 32768 )
{
turn torso to y-axis heading speed <300.0>;
}
if ( heading_01 > 32768 )
{
turn torso to y-axis 0 - heading speed <300.0>;
}
Well... this code no longer seems to help any. There's something very funky in the way that restricted-arc weapons are being aimed by Spring... it's almost like it's checking to see if they've passed their maximum-allowed angle, along with everything else- and if they have, instead of *stopping* their rotation, which is what they should do, they're attempting to rotate back to 0 Y

So, I checked through the code...
...hmm... this is interesting, and might be where this odd behavior starts (from Weapon.cpp):
If I'm reading this right, then this argument, unlike OTA, will return a short, instead of a short int, which means that the number returned is frequently negative. So therefore, if I write my code like this:
... it should work.
<tests>
Nope, the exact same problem is occurring- it keeps trying to return to 0 Y.
Code: Select all
short int heading=GetHeadingFromVector(wantedDir.x,wantedDir.z);
short int pitch=(short int) (asin(wantedDir.dot(owner->updir))*(32768/PI));
std::vector<int> args;
args.push_back(short(heading-owner->heading));
args.push_back(pitch);
owner->cob->Call(COBFN_AimPrimary+weaponNum,args,ScriptCallback,this,0);
Code: Select all
heading_01 = heading;
if ( heading_01 < 0)
{
turn torso to y-axis heading speed <300.0>;
}
if ( heading_01 >= 0)
{
turn torso to y-axis 0 - heading speed <300.0>;
}
<tests>
Nope, the exact same problem is occurring- it keeps trying to return to 0 Y.