# Does sdk have angle(x1,y1,x2,y2) function?

For developers using the Construct 2 Javascript SDK

### » Sun Apr 06, 2014 9:22 pm

Is there is an equivalent to the angle(x1,y1,x2,y2) expression built into the sdk? Trivial to do manually I guess, but if there's an internal command, I'd rather use it.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

### » Sun Apr 06, 2014 9:53 pm

https://developer.mozilla.org/en-US/doc ... Math/atan2

its essentially just this function, but to make it work like angle(x1,y1,x2,y2) something like this should work:

Math.Atan2(x2-x1,y2-y1)/(2*Math.PI) (you can omit the math.pi thing if you want the angle in radians rather than degrees)
B
77
S
13
G
8
Posts: 1,974
Reputation: 9,893

### » Mon Apr 07, 2014 12:26 am

Yes, you could trace that expression to get the cr.angle （might be this name).
B
108
S
26
G
272
Posts: 4,472
Reputation: 152,279

### » Mon Apr 07, 2014 5:37 am

@QuaziGNRLnose

Thanks, that looks like it'll work fine. I'm just starting to learn javascript; I didn't know it had math functions like atan built in. Guess I have a bit to learn...

@rexrainbow

I could do that...but I'd be worried that it might break later on. If it's not a documented part of the sdk, there's no guarantee on fixed syntax, right? Or, maybe I'm worrying too much.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

### » Mon Apr 07, 2014 6:28 am

The function is cr.angleTo(x1, y1, x2, y2) and it's in common_prelude.js. It's a helper function that is used throughout the runtime, so the likelihood of it breaking later on is near zero. There are also a lot of other functions in that file that can by useful.
B
92
S
32
G
109
Posts: 5,294
Reputation: 70,999