- Home /
Question by
NerdRageStudios · Mar 29, 2018 at 10:02 AM ·
anglevector2
How to get input as a Vector2 from a direction
Hi, I use the following code to rotate the gun in my 2D Game...
rot = Mathf.Atan2(lastStickPos.y, lastStickPos.x) * Mathf.Rad2Deg;
Easy. But I am coding AI bots now, and I want them to use the same input class to move, so I need to feed a Vector2 of a virtual stick input for them to aim.
I use this to get the angle I need to aim in.
float ang = Vector2.Angle(fromVector2, toVector2);
Vector3 cross = Vector3.Cross(fromVector2, toVector2);
if (cross.z > 0)
ang = 360 - ang;
But I cant work out how to to convert the result to a Vector2 Input...
Any ideas?
Comment
Your answer
Follow this Question
Related Questions
Weird angle returned 1 Answer
Constructing a Vector in 2-space from an angle for camera panning 1 Answer
Using "rigidbody.AddForce" to throw an object towards a target - iOS 1 Answer
Get angle between 2 Vector2's 5 Answers
Adjusting an angle of a collider2D to a linerenderer that is user-created 0 Answers