aimAngle > 0 ? aimAngle : (18+(18-abs(aimAngle)))[/code:vqkqin9w]
Actually, that looks complicated, but what it does, is simple.
The thing is:
In my .capx, I use the [b]angle expression[/b] to determine the way the turret has to look and, thus, which animation frame to use.
A problem with the [b]angle[/b] expression is that it doesn't return the angle from 0-360, but from 0-180 and from -180-0.
Look at this (notice how the angle goes negative and decreases when it should stay positive and increase):
Now, to use the variable [i]aimAngle[/i] for the animation frames, it needs to have the range 0-360 (because the animation frames go from 0 to 36), not 0-180 & -180-0.
That's why I need to convert [i]aimAngle[/i] to a positive value each time it is below 0 (i.e. negative and not usable).
(in my .capx, the 18 actually stands for 180 degrees. Since [i]aimAngle[/i] is already the normal angle divided by 10, it's 18 in the code. But I'll refer to 180 in the following since everything else is easier to understand then)
Since you now know what the [b]?[/b] does, I'll only look at [b](180+(180-abs(aimAngle)))[/b]
which is the conversion from everything from -180-0 to 180-360.
[u]Let's take an example:[/u]
[i]aimAngle[/i] is -170.
We need it to be 190 (according to what I mentioned above).
Initial code looks like this:
First of all, we need to make the negative [i]aimAngle[/i] positive. We do so by using [i]abs[/i].
Now, [i]aimAngle[/i] is positive and we have this: [b](180+(180-170))[/b]
Now, we substract [i]aimAngle[/i] from 180 to get the rotation that needs to be done to go from 180 to the [i]aimAngle[/i] we want (190).
That leaves us with this: [b](180+10)[/b]
And there we go: 190 is the result, exactly what we want.
I hope, I was clear enough.
[b]Got any more questions? PM me, please, so we don't have to spam this thread with off-topic stuff. ;)[/b]