How do I find the angle between two points

Get help using Construct 2

Post » Thu Aug 10, 2017 3:26 am

So I've made a little GPS like system for my program and have AI moving from point to point based on that instead of the actual coordinate system used in the construct 2 editor. How can I find the angle of the line between two points so my bots know which way to go? (the built in angle function leads to my bots getting stuck sometimes)
Edit: I've tried using the atan function but it only works for angles between 90 to 270
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Sat Aug 12, 2017 9:02 am

set player angle to, (a, b, c, d)
a, b coordinates of first point, and c,d coordinates of the second point
'Image'Image'Image
B
20
S
6
G
2
Posts: 99
Reputation: 2,503

Post » Sat Aug 12, 2017 10:57 am

Are the graphics of the bots lined up with the zero angle ?
In C2 that zero angle is to the right. (east)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Aug 12, 2017 8:43 pm

I can't use angle(a,b,c,d). My GPS doesn't line up with the actual points in the editor so if I use angle it won't be correct. I read that in a lot of programs there's a function called Atan2 but Construct doesn't have it and the graphics are lined up with the 0 degree position
B
22
S
8
Posts: 203
Reputation: 2,059

Post » Sat Aug 12, 2017 9:01 pm

angle(x1,y1, x2,y2) is the same as atan2(y2-y1, x2-x1)
B
94
S
33
G
114
Posts: 5,360
Reputation: 73,781

Post » Sat Aug 12, 2017 9:06 pm

Oh my god, I'm an idiot XD I forgot that when using atan2 you have to do the subtraction to make it into 2 variables, no wonder it wasn't working. Thank you!
B
22
S
8
Posts: 203
Reputation: 2,059


Return to How do I....?

Who is online

Users browsing this forum: mekonbekon, Yahoo [Bot] and 9 guests