This function allows you to calculate the angle between two vectors without having to deal with Trigonometric functions, but it has a downside. The way it works is not as clear as one could wish.

I used this function to allow an agent (I.A.) to choose among the exits in a dungeon room. I needed the agent to be able to recognize the exits to his left or right.
I created a list containing the exits positions, I needed a way to sort them out in a clockwise order, here is where Vector2.Angle comes into play. After some debugging I realized that I couldn’t jut use positions to calculate this. Specially considering that whenever an agent enters a room he is facing a specific direction, therefore the exit to its right would depend of where it is facing at that moment.
Unity Vector2 C#
- Unity rotate vector. Csharp by TC5550 on May 23 2020 Donate. Rotate vector3 around pivot point unity. Csharp by PutterBeanut on Dec 03 2020 Donate. 1 Source: answers.unity.com. Add a Grepper Answer. C# answers related to “rotate a vector2 unity”.
- In this tutorial, we go over how to use our brand new Vector Field Plugin for unity. We re-coded this plugin from scratch to create what is now version 2.0.T.
- The Vector2 structure provides support for hardware acceleration. For matrix transformations, the Vector2, Vector3, and Vector4 instances are represented as rows: a vector v is transformed by a matrix M with vM multiplication.
- Unity Int Vectors. This library provides integer vectors, Vector2i and Vector3i. These are integer variants of Unity's Vector2 and Vector3 classes and implement all functionality that you would expect. A familiar interface. Vector2i and Vector3i use the same interface as Vector2 and Vector3.

I created a scene where I could test this, here are some screenshots in which you can see that the agent at the centre is facing a specific direction (in this case I restricted it to North, South, East or West).
In order to correctly use Vector2.Angle you need to input direction vectors. In my case one of them is the direction the agent is facing and the second one is created from the agent and exit’s position.
A vector V that goes from A to B is created by subtracting A from B. V = B – A.
The angle returned from Vector2.Angle is a result from the dot product of the vectors therefore it’s values are between 0 and 180.
With the variable “orientation” we find out if it is going clockwise or counter clockwise. With this knowledge at hand we can get the angle value in a 360 degree format.

Unity Vector2 Lerp
C# / Unity Vector2 rotation 2015-03-07 03:20:54 Making a simple asteroids type game to get more comfortable with C# and Unity. I have the asteroids falling from the top of the screen after I instantiate them randomly from spawn points and it all works great.
Unity Vector2 Magnitude
Feel free to download browse the attached project and comment any questions you might have.
