Hey all.
Let’s say I have a vector, for example Vector2(1, 0.5f) and I would like to set Z rotation of a Transform according to that vector. How can I achieve that?
Thank you.
where you able to find how? im faceing the same issue today, i have a vector2 for x and y. And want to use the angle between x and that vector to rotate my object around z axis
The solution :
- Get your Input X and Y.
- then convert it to rad
- convert this rad to deg
- (if you need an offset, do it here)
- Assign the result to Z Angle rotation
Code to convert
public Vector2 v2;
public float angle;
Void DoConversion()
{
float radvalue = Mathf.Atan2(v2.y,v2.x);
angle= radvalue * (180/Mathf.PI);
}