Make system expression angle(x1,y1,x2,y2) to return 0-360?

Get help using Construct 2

Post » Tue Mar 03, 2015 3:36 pm

As angle system expression returns value 0 to 180 then -180 to 0 clockwise. How to make it return 0-360 instead ? :?:
B
5
Posts: 16
Reputation: 259

Post » Tue Mar 03, 2015 3:49 pm

You can use conditionals, but the expression usually comes out fine math wise.
Image ImageImage
B
171
S
50
G
179
Posts: 8,382
Reputation: 113,458

Post » Tue Mar 03, 2015 4:04 pm

If you need 0-360 for purposes of comparisons, etc., it can be normalized from 0-360 using:
(Angle % 360 + 360) % 360
B
31
S
7
G
8
Posts: 232
Reputation: 6,274

Post » Tue Mar 03, 2015 4:47 pm

Thanks, that works! I don't know why it work...Can you give me the direction where to study "%" operation like that. My highschool math class does not have thing like that.
B
5
Posts: 16
Reputation: 259

Post » Tue Mar 03, 2015 7:11 pm

It shouldn't matter if you do your math right. All angular operations should be cyclical so it doesn't matter if it returns -180 to 180 or 0 to 360. (Unless you display the result to the user.)
Scirra Founder
B
399
S
236
G
89
Posts: 24,525
Reputation: 195,382

Post » Tue Mar 03, 2015 7:42 pm

I use angle to drive animation frame so i want full absolute 360 degree.
B
5
Posts: 16
Reputation: 259

Post » Tue Mar 03, 2015 8:42 pm

The % is the modulo operator. It gets the division remainder between two numbers.
For example: 375 % 360 = 15, 360 % 360 = 0, 90 % 360 = 90, etc.

Step 1: Angle % 360
Single angle could be negative or positive, the first modulo returns a remainder between -359 to +359 degrees.
Step 2: Add 360 degrees
Returns the positive quadrant equivalent: (ex: -90 degrees would be pointing upward, this returns 270 degrees)
Step 3: % 360
If original angle was positive, step 2 would have caused it to exceed 360 degrees, so take the modulo again.


More information: http://stackoverflow.com/questions/1351925/why-does-2-mod-4-2
B
31
S
7
G
8
Posts: 232
Reputation: 6,274

Post » Tue Mar 03, 2015 9:15 pm

Thank you very much ,now this modulo thing make sense to me.
B
5
Posts: 16
Reputation: 259

Post » Tue Mar 03, 2015 9:29 pm

Thats actually a little scary. Hope you don't use 360 frames.
Image ImageImage
B
171
S
50
G
179
Posts: 8,382
Reputation: 113,458


Return to How do I....?

Who is online

Users browsing this forum: chrisinfinger and 21 guests