Comments and answers for "calculate Vector3 offset relative to surface normal"
http://answers.unity.com/questions/655659/calculate-vector3-offset-relative-to-surface-norma.html
The latest comments and answers for the question "calculate Vector3 offset relative to surface normal"Comment by vik.vega on vik.vega's answer
http://answers.unity.com/comments/655766/view.html
yes ! the second solution is more like it ! :) Maybe since the raycast is from the camera, camera transform could be taken into account.
Anyway thanks again, i'm testing your hints right now !Wed, 05 Mar 2014 02:34:04 GMTvik.vegaComment by robertbu on robertbu's answer
http://answers.unity.com/comments/655760/view.html
> You may have missed the part where i
> already thougth about using an empty
> object, aligning it, and using it's
> points to cast rays.
Didn't miss it, but thought that you were talking about a real object of some sort rather than an empty game object with the reference to 'resizing'. Let me throw out another solution. For it to work you need either 1) one additional point on the plane, or 2) any vector that is not the same as the normal (and can be generated randomly). Using the second, you can do:
var dir = Vector3.Cross(hit.normal, otherVector).normalized;
var pos1 = hit.point + dir;
var pos2 = hit.point + Quaternion.AngleAxis(90,hit.normal) * dir;
var pos3 = hit.point + Quaternion.AngleAxis(180,hit.normal) * dir;
var pos4 = hit.point + Quaternion.AngleAxis(270,hit.normal) * dir;
Or this should work:
Quaternion q = Quaternion.FromToRotation(Vector3.up, hit.normal);
var pos1 = hit.point + q * Vector3(1,0,1);
var pos2 = hit.point + q * Vector3(-1,0,1);
var pos3 = hit.point + q * Vector3(-1,0,-1);
var pos4 = hit.point + q * Vector3(1,0,-1);Wed, 05 Mar 2014 02:24:05 GMTrobertbuComment by vik.vega on vik.vega's answer
http://answers.unity.com/comments/655721/view.html
Thanks for your time, robertbu!
You may have missed the part where i already thougth about using an empty object, aligning it, and using it's points to cast rays.
What I'm interested in understanding, is how to achieve this, working with the vectors i have, being hit.point and hit.normal
But you're right, I may have not defined completely the conditions: I want the lines to be parallel to hit normal, "sliding" over the surface with a given offset.Wed, 05 Mar 2014 01:29:24 GMTvik.vegaAnswer by robertbu
http://answers.unity.com/answers/655714/view.html
There are a lot of different ways of solving this problem. One issue is that you have a degree of freedom here you did not define. That is the four red lines may be rotate to any arbitrary angle with the green normal as the axis. If you don't care about that rotation, then a really simple approach is to use an empty game object (with a scale of (1,1,1)). Then you can do:
empty.transform.position = hit.point;
transform.up = hit.normal;
var pos1 = empty.transform.TransformPoint(Vector3(1,0,1));
var pos2 = empty.transform.TransformPoint(Vector3(-1,0,1));
var pos3 = empty.transform.TransformPoint(Vector3(-1,0,-1));
var pos4 = empty.transform.TransformPoint(Vector3(1,0,-1));Wed, 05 Mar 2014 01:16:20 GMTrobertbu