angle difference in both directions?

Get help using Construct 2

Post » Sun Nov 09, 2014 6:42 pm

How do i get the difference between 2 angles both clockwise and counterclockwise?

I want to compare the 2 to test if it's quicker to rotate an object left or right from its current angle to its target angle in degrees.

I thought you could negate the anglediff expression but it still only calculates the shortest difference.

Thanks.
B
43
S
23
G
20
Posts: 735
Reputation: 12,027

Post » Mon Nov 10, 2014 2:47 am

This will give a signed angle diff between two angles.
angle(0,0,cos(a-b),sin(a-b))

It's in the range of -180 to 180. It always picks the shortest distance but it's negative if CCW and positive if CW.

Alternatively you could leverage the CW and CCW conditions or calculate if the angle diff is CW or CCW with
(sin(a-b)<0?-1:1)


global sign=1
global short_angdiff=0
global long_angdiff=0

every tick
--- set sign to (sin(a-b)<0?-1:1)
--- set short_angdiff to anglediff(a,b)*sign
--- set long_angdiff to (360-anglediff(a,b))*-1*sign
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Mon Nov 10, 2014 9:35 am

Brilliant as always, thanks for your help.
B
43
S
23
G
20
Posts: 735
Reputation: 12,027

Post » Mon Nov 10, 2014 10:03 am

our R0J0hound is always there to help bless
B
250
S
39
G
15
Posts: 1,953
Reputation: 40,623


Return to How do I....?

Who is online

Users browsing this forum: blackhornet, evillair, NumberOne, Solomon and 5 guests