Comments and answers for "Find Vector3 perpendicular to Vector3 A in direction of Vector3 B"
http://answers.unity.com/questions/730156/find-vector3-perpendicular-to-vector3-a-in-directi.html
The latest comments and answers for the question "Find Vector3 perpendicular to Vector3 A in direction of Vector3 B"Comment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1587887/view.html
I think your confusing two things (which technically are the same but represent something else): The position of your two spheres are points in space. Project / ProjectOnPlane works with direction vectors only. Passing just two position vectors to any of those function most likely won't give you what you want. $$anonymous$$eep in mind that position vectors start at the world origin.
<br>
It's hard to see in your gif but it looks like the object is not flat in that area where the indent is located. This would make it quite difficult to pick proper reference points / reference space.
<br>
I guess you have a mesh collider, otherwise this wouldn't make much sense. The best result you would get by grabbing the surface normal of one of the hit points as normal vector. Then just use `Vector3.Project(hit2,point - hit1.point, hit1.normal)` this gives you the depth of the indent. It may be negative, depending on where you place the first and the second point. To get a positive result with this example the first point need to be in the indent, the second outside. Though you may simply want to use `Mathf.Abs()`.
<br>
If you don't want to use the normal of one of the hits, you would need to place 4 points in total in order to get any meaningful reference frame and a point to test. Two points define just a single direction in space. 3 points which define 2 linearly independent directions form a coordinate space which can be used as reference. However those 3 initial points would dictate the orientation of the coordinate system. So their placement is crucial. Using the surface normal is much easier. Though since your mesh is not flat the placement of the two points must not be too far apart, otherwise the curvyness of the mesh produces errors.
<br>
Please, if you need any further help, ask a seperate question.Tue, 08 Jan 2019 09:34:50 GMTBunny83Comment by jvhgamer on jvhgamer's answer
http://answers.unity.com/comments/1587782/view.html
@Bunny83 ![sample][1] Unsure if this is what I am looking for. Would you mind clarifying using my example visual? In the short clip there are two points being placed. The first point is green, the second red. The desire is to calculate the depth of the indent on this model. The first solution that comes to mind is to select a point in the depth of the indent and another outside of it. Now using these two points and the distance between them can we use ProjectOnPlane() to calculate the third point going parallel from the point outside the indent, and vertical from the point in the indent? I'm thinking if this is possible it's than a distance calculation between the point inside the indent and this third point to determine the depth of the indent. Again, unsure if this is entirely too complicated but this is, part of, the solution that comes to mind. Please advise, if on the right track, how to use the method properly, or if not, if there's an alternative solution I'm not seeing. As of now, using ProjectOnPlane to create a third point but it's not appearing where I'd expect this third point to be.
[1]: https://i.ibb.co/kh8Vwtx/Indent-Test.gifTue, 08 Jan 2019 00:59:48 GMTjvhgamerComment by normalmaps on normalmaps's answer
http://answers.unity.com/comments/1208151/view.html
I love you!! <3
I didn't even know what a projection was, but now I do, thanks!
+1Sat, 25 Jun 2016 20:14:49 GMTnormalmapsComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/730192/view.html
@MoyaAdam: Great you got it working. Does that mean your question is answered? In that case:
<img src="https://dl.dropboxusercontent.com/u/7761356/UnityAnswers/Images/HowToTickAnAnswer.PNG">
:) thxWed, 18 Jun 2014 21:47:11 GMTBunny83Comment by MoyaAdam on MoyaAdam's answer
http://answers.unity.com/comments/730190/view.html
Just got it working, you saved me a lot of frustation working with dot products. Thank you!Wed, 18 Jun 2014 21:37:46 GMTMoyaAdamComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/730182/view.html
Wow, strange how much nonsense you find when searching for "project vector onto plane", however here's a good visualization of the process:
http://my.safaribooksonline.com/book/illustration-and-graphics/9781558605947/chapter-12-miscellaneous-3d-problems/head1_id_93Wed, 18 Jun 2014 21:28:46 GMTBunny83Answer by Bunny83
http://answers.unity.com/answers/730174/view.html
You just need to project your vector B onto the plane with the normal vector A
All you actually need is the dot product, however your vector A need to be normalized. Unity provides a well optimised method which projects a vector onto a given normal, even when it's not normalized: [Vector3.Project()][1].
All you need to do is subtract the projected vector B from the original vector B:
// C# / UnityScript
var vec = B - Vector3.Project(B,A);
If you want the new "vec" to have the same length as the old B you can do this afterwards of course:
vec = vec.normalized * B.magnitude;
***edit***
Since the question got already bumped i should add that Unity recently added a dedicated method for this kind of projection: [Vector3.ProjectOnPlane][2].
The method literaly is implemented the same way as my solution above, so it's just a bit simpler to use:
var vec = Vector3.ProjectOnPlane(B,A)
[1]: http://docs.unity3d.com/ScriptReference/Vector3.Project.html
[2]: https://docs.unity3d.com/ScriptReference/Vector3.ProjectOnPlane.htmlWed, 18 Jun 2014 21:15:02 GMTBunny83Comment by AndyMartin458
http://answers.unity.com/comments/730163/view.html
http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-2/Wed, 18 Jun 2014 20:51:21 GMTAndyMartin458Comment by AndyMartin458
http://answers.unity.com/comments/730162/view.html
I meant to say the cross product. http://docs.unity3d.com/ScriptReference/Vector3.Cross.htmlWed, 18 Jun 2014 20:50:10 GMTAndyMartin458