@gamecorpstudio

- Code: Select all
`aimAngle > 0 ? aimAngle : (18+(18-abs(aimAngle)))`

Actually, that looks complicated, but what it does, is simple.

The thing is:

In my .capx, I use the

angle expression to determine the way the turret has to look and, thus, which animation frame to use.

A problem with the

angle 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

aimAngle 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

aimAngle 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

aimAngle 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

? does, I'll only look at

(180+(180-abs(aimAngle)))which is the conversion from everything from -180-0 to 180-360.

Let's take an example:aimAngle is -170.

We need it to be 190 (according to what I mentioned above).

Initial code looks like this:

(180+(180-abs(-170)))First of all, we need to make the negative

aimAngle positive. We do so by using

abs.

Now,

aimAngle is positive and we have this:

(180+(180-170))Now, we substract

aimAngle from 180 to get the rotation that needs to be done to go from 180 to the

aimAngle we want (190).

That leaves us with this:

(180+10)And there we go: 190 is the result, exactly what we want.

I hope, I was clear enough.

Got any more questions? PM me, please, so we don't have to spam this thread with off-topic stuff. ;)
"We can't solve problems by using the same kind of thinking we used when we created them."

- Albert Einstein