How do I rotate isometric turret ?

Get help using Construct 2

Post » Sun Nov 27, 2016 2:39 pm

HI GUYS, I don't get it...I tried so many things... You can see my turret with 36 frames...it should animate every 10 degrees...and shoot in the direction of the target...please help ! :) thanks

capx is here : https://lookaside.fbsbx.com/file/tank%2 ... 4873gcm58k
B
37
S
16
G
2
Posts: 447
Reputation: 4,865

Post » Sun Nov 27, 2016 6:01 pm

The current Turret behaviour can't use frames to animate the rotation.
You will have to do the rotation yourself.

Take a look at this .capx:
Download .capx

The bullet angle is a bit off, but we could correct that with a dictionary or some advanced calculations.
(If you want, I can show you how)

(By the way, your initial Animation strip missed a frame between 24 and 25, I replaced that with a duplicate of 24 to correct the calculations. And I also corrected the origin of the bullet sprite, it was a bit off)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sun Nov 27, 2016 8:38 pm

thanks a lot 4 ur great help!
B
37
S
16
G
2
Posts: 447
Reputation: 4,865

Post » Tue Nov 29, 2016 2:13 pm

edited: nevermind the solution was already posted ... by randomly

by the way @randomly... what is the ? meaning in the angle formula you used never seen it before in C2.... what the expression mean?

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


and im reffering to the
Code: Select all
0 ? aimangle :
part of it


Edited2: found the manual expression but still want to understand your code
B
78
S
23
G
69
Posts: 1,353
Reputation: 43,985

Post » Tue Nov 29, 2016 5:48 pm

@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):
Image

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
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Tue Nov 29, 2016 6:24 pm

@randomly

i see now makes more sense :D learned a few things how to avoid checking negative numbers hehe, also i understand now what that
Code: Select all
 ? :
means better and how to use properly! Thanks man.
B
78
S
23
G
69
Posts: 1,353
Reputation: 43,985


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, valefor and 6 guests