I had a little bit more time so using an online graphing calculator I went back so see if I could get a better approximation using my earlier idea:
For instance, using the approximation I listed above for a projectile with a speed of 15scroton wrote:I suppose you could have jumps in decorate to have it use different pitch formulas depending upon what it's momz is, and that might be most accurate of all.

You can see that the approximation (4x) follows the actual pitch (arcsin(x/15)) pretty closely for ~2/3 of the range, then diverges a bit at the far ends.
However, using just one more simple linear function you can approximate that portion where it starts to diverge pretty closely.

Here it is at both ends:

And truncated with range restrictions for easier viewing. Next to it is the original approximation again for comparison:

And here is the decorate code for a projectile with speed 15 to use that approximation method instead of the original one:
Code: Select all
Spawn:
TNT1 A 0
TNT1 A 0
TNT1 A 0 A_JumpIf(MomZ > 10, "Spawn2")
TNT1 A 0 A_JumpIf(MomZ < -10, "Spawn3")
TNT1 A 0 A_SetPitch(MomZ*4)
Goto Spawn4
Spawn2:
TNT1 A 0 A_SetPitch(MomZ*9 - 52)
Goto Spawn4
Spawn3:
TNT1 A 0 A_SetPitch(MomZ*9 + 52)
Goto Spawn4
Spawn4:
TNT1 A 1
LoopOf course, after finishing the above, I realized that the same thing can be done in ACS, so I wrote the following script that sets the pitch of the calling actor to the appropriate pitch. This should be accurate rather than an approximation:
Code: Select all
//Not my function, from
//http://zdoom.org/wiki/Sqrt
//Not needed in zdoom
function int sqrt(int number)
{
if(number <= 3) { return number > 0; }
int oldAns = number >> 1, // initial guess
newAns = (oldAns + number / oldAns) >> 1; // first iteration
// main iterative method
while(newAns < oldAns)
{
oldAns = newAns;
newAns = (oldAns + number / oldAns) >> 1;
}
return oldAns;
}
//My script
script 1 (void)
{
int finfgfzzgngXa = FixedMul([PROJECTILE_SPEED_x_65536],[PROJECTILE_SPEED_x_65536])-FixedMul(GetActorVelZ(0),GetActorVelZ(0)); //Put fixed-point projectile speed here
int finfgfzzgngX = sqrt(finfgfzzgngXa);
int finfgfzzgngZ = GetActorVelZ(0);
int finfgfzzgngA = VectorAngle (finfgfzzgngX, finfgfzzgngZ);
SetActorPitch(0, finfgfzzgngA);
Terminate;
}A while back I went and tried to solve this even better with a matrix but while it spits out a solution that matches the actual pitch pretty closely it still isn't as accurate as the 3 linear equations at approximating the pitch. Might be worth it if you didn't want to use jump states I suppose, since even though it's inaccurate compared to the linear equations it's still a single expression and that might be desired in certain situations.