Vector2 from an angle

This is actually an extremely important and teachable point… games are all over the place on this point, and every engine is a little different. For instance Unity is a left-handed engine (look up what that means on google), and it has conventions about what rotations do and which way is considered “zero.”

I try to make most of my games have zero point directly north with angles going clockwise, a throwback to olden day sprite systems, but any mathematics text or scientific text will have zero generally point right and angles going counter-clockwise around.

The key takeaways are a) know the difference between radians and degrees, b) when you start writing code like this, immediately write a quick test case that outputs to Debug.Log() so you can verify.

DO NOT PROCEED until you are happy with which way is zero, as well as whether things are winding clockwise or counter-clockwise, or you will be very confused and end up sprinkling warts all over your code to back offsets out, like adding +90 and crud like that. Just say no to code warts and get the underlying math 100% right first.

And remember the opposite of doing sin/cos is doing atan2(), which takes a (y,x) (not an x,y!) and gives you an angle, which is of course in radians, not degrees. Get so comfortable with sin/cos/atan2() that you can explain it to your grandmother over tea and crumpets and then rotations will be a breeze for you.

Convert between radians and degress by multiplying by Mathf.Rad2Deg or Mathf.Deg2Rad

4 Likes