# Construct 2 Angle Code

Discussion and feedback on Construct 2

### » Thu Aug 13, 2015 7:10 am

in construct two there is a function called angle with four parameters where you can get the angle between two objects (reference from rotating platformer) , I want someone to provide me the code that function because I want to use it in a JavaScript program and I don't know how.
B
59
S
18
G
5
Posts: 852
Reputation: 11,746

### » Thu Aug 13, 2015 9:07 am

Look for function atan2 which takes dy and dx as parameters.
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

### » Thu Aug 13, 2015 1:17 pm

paulscottrobson wrote:Look for function atan2 which takes dy and dx as parameters.

Just to add onto this, the atan2 function will return radians. To get to degrees, multiply by (180/pi):

Code: Select all
` var degrees = Math.atan2(y2-y1,x2-x1) * (180/Math.PI);`

You could have undoubtedly found this solution by googling "Calculate angle between 2 points in javascript".
B
67
S
21
G
8
Posts: 341
Reputation: 12,560