Comments and answers for "How to calculate vector perpendicular to a direction vector?"
http://answers.unity.com/questions/1203255/how-to-calculate-vector-perpendicular-to-a-point-o.html
The latest comments and answers for the question "How to calculate vector perpendicular to a direction vector?"Answer by unity_ioeaHQCQ0I7G2A
http://answers.unity.com/answers/1662697/view.html
In 2D:
direction vector = (x,y) =>
normal vector = (-y,x) or (y,-x)
In 3D:
direction vector = (x,y,z) =>
normal vector (in plane y, y stay) = (-z,y,x) or (z,y,-x)Tue, 03 Sep 2019 05:56:57 GMTunity_ioeaHQCQ0I7G2AComment by NoseKills on NoseKills's answer
http://answers.unity.com/comments/1203361/view.html
That's the same as cross product basically.
> the cross product will give you a vector perpendicular to both the input vectors, so it's useless in 2D.
Awww. you were so close :) this "problem" is in fact the solution.
Cross product works perfectly for 2D if you just use Vector3.forward (or 'back') as the reference vector (it can never have the same direction as your other 2D vector so you don't have that problem).
The 2 vectors you input to get a cross product define the plane to which the result is a normal for. If the 2 input vectors are the same or one of them is zero, they don't define a plane so there is no normal either.
P.S. I don't want to encourage anyone to prematurely optimize working code, but cross product is probably 20 times faster than quaternions for this performance wiseWed, 15 Jun 2016 21:47:50 GMTNoseKillsComment by AndrewRyan on AndrewRyan's answer
http://answers.unity.com/comments/1203330/view.html
Thanks, WinterBlood. Are you effectively rotating the vector by doing that- i'm not sure? If not, I managed to fix it by using Quaternion.AngleAxis to rotate the direction vector 90 degrees.Wed, 15 Jun 2016 20:57:39 GMTAndrewRyanAnswer by Winterblood
http://answers.unity.com/answers/1203279/view.html
If it's in 2D you can just swap the components and negate one:
blueVector.x = redVector.y;
blueVector.y = -redVector.x;
(You'll probably then want to normalise it so it's a consistent magnitude)
FWIW, the cross product will give you a vector perpendicular to both the input vectors, so it's useless in 2D.
[EDIT] BTW, if you keep adding that tangential velocity it will spiral rapidly outwards, even with damping. I'm guessing you might want it to orbit, in which case you'll need a "gravity" force to stop it flying off.Wed, 15 Jun 2016 19:46:51 GMTWinterblood