# 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
45
S
10
G
11
Posts: 1,106
Reputation: 9,732

### » 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
79
S
13
G
8
Posts: 1,977
Reputation: 9,947

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

Yes, you could trace that expression to get the cr.angle （might be this name).
Goodbye
B
114
S
31
G
295
Posts: 4,549
Reputation: 164,608

### » 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
45
S
10
G
11
Posts: 1,106
Reputation: 9,732

### » 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
100
S
38
G
134
Posts: 5,556
Reputation: 85,325

### Who is online

Users browsing this forum: No registered users and 1 guest