S
S
sstas2020-10-13 14:45:54
C++ / C#
sstas, 2020-10-13 14:45:54

How to get the remainder of a division if the left number is less than the right?

Greetings, there was a need to determine in Unity the slope of an object with a rotation step of 45 degrees, i.e. 0, 45, 90, etc.
How to determine that the angle is 45, 135, 225...?
The first thing that came to mind was to use the remainder of the division, but if you use 45, then it will always be 0, and 90 does not work in the case of 45% 90, because will be 45, instead of 5, the question follows:
How to get the remainder of the division, if the left number is less than the right one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-10-13
@sstas

(angle / 45)%2 - if the result is 0 - then it stands "exactly", if the result is 1 - then diagonally. You can take the module from the corner so as not to worry about negative ones.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question