# (solved) Angle in turret behavior

Get help using Construct 2

### » Thu Sep 19, 2013 7:41 pm

hi there :D!

I'm having trouble figuring this out.

I'm making a RTS type game. And my sprites have several frames to show which angle they're looking at using the "MovingAngle" expression of the pathfinding behavior.
For example this: "round((unit.Pathfinding.MovingAngle+45)/45)"
That particular unit has 9 frames (frame 0 is empty). And it works fine :D

However, they also have the turret behavior, so they use their pathfinding.MovingAngle when they don't have targets, but for when they do have targets, I don't know what to do. The "angle(x1,y1,x2,y2) expresion only give me negative numbers from 0 to -180, unlike MovingAngle that returns 0 to 360. So I can only use half the angles when in range.

The idea is that when they have targets they look at them when they move.

I hoped something like this: "round((angle(unit_Builder.X,unit_Builder.Y,F_Enemy.X,F_Enemy.Y))/45)" might have worked. but it doesn't =(

Any suggestions? Am I missing something? D:

(just in case, i AM using the pick target by UID)Sargas2013-09-19 23:24:53
B
43
S
12
G
6
Posts: 446
Reputation: 6,807

### » Thu Sep 19, 2013 11:24 pm

ok, I figured it out... i just had to add a +180 on the calculation....

-180+180 = 0
180 + 180 = 360

and there i go.

stupid angle expression.

"round((angle(unit.X,unit.Y,Enemy.X,Enemy.Y))/45)"

I also had something else wrong.
This is the correct form:

"round(angle(Enemy.X,Enemy.Y,unit.X,unit.Y)+180)/45"

or the result is inverted =(Sargas2013-09-19 23:34:08
B
43
S
12
G
6
Posts: 446
Reputation: 6,807