Comments and answers for "Snap a direction vector"
http://answers.unity.com/questions/493006/snap-a-direction-vector.html
The latest comments and answers for the question "Snap a direction vector"Comment by ThomasSoto on ThomasSoto's answer
http://answers.unity.com/comments/1629212/view.html
Hey Robert, could you take a look at this post? It's based on this answer but with a small tweak that I'm in need of to shift the snap angles.
https://answers.unity.com/questions/1629211/snap-direction-to-angles-shifting.htmlMon, 06 May 2019 21:45:27 GMTThomasSotoComment by Rabwin on Rabwin's answer
http://answers.unity.com/comments/493398/view.html
The cross product for the rotation axis! Oh my god I'm so dumb I can't believe I forgot that already. Looks like the maths units I did have completely gone to waste hahaha!Mon, 15 Jul 2013 13:54:22 GMTRabwinAnswer by robertbu
http://answers.unity.com/answers/493139/view.html
Here is a SnapTo() methods that snaps the vector to the specified angle. It works by generating the cross product between the direction and Vector3.up to create an axis for rotation. Then it does an AngleAxis rotation to snap the vector to the angle.
Vector3 SnapTo(Vector3 v3, float snapAngle) {
float angle = Vector3.Angle (v3, Vector3.up);
if (angle < snapAngle / 2.0f) // Cannot do cross product
return Vector3.up * v3.magnitude; // with angles 0 & 180
if (angle > 180.0f - snapAngle / 2.0f)
return Vector3.down * v3.magnitude;
float t = Mathf.Round(angle / snapAngle);
float deltaAngle = (t * snapAngle) - angle;
Vector3 axis = Vector3.Cross(Vector3.up, v3);
Quaternion q = Quaternion.AngleAxis (deltaAngle, axis);
return q * v3;
}Mon, 15 Jul 2013 01:29:22 GMTrobertbuComment by Rabwin
http://answers.unity.com/comments/493112/view.html
I apologize, I have added some of my actual code and an image to hopefully demonstrate my goal.Sun, 14 Jul 2013 23:48:51 GMTRabwinComment by nsxdavid
http://answers.unity.com/comments/493085/view.html
Yeah the question doesn't make much sense. Show some code of what you are doing now.Sun, 14 Jul 2013 22:52:31 GMTnsxdavidComment by robertbu
http://answers.unity.com/comments/493060/view.html
I'll be glad to help if you can explain more about the problem. A drawing would help. When you say "snapped to the nearest45 degrees on the y" I visualized using the 'y' as an axis and snapping to angles on this axis. But further you say "find the angle between the direction and the down vector", which does not map very well to my understanding. So what world axis is the axis of rotation for the vector?Sun, 14 Jul 2013 22:22:04 GMTrobertbu