Hi !
I’m trying to calculate four relative points from a raycast hit point, according to the face normal that was hit.
Now the offsets in the code are obviously wrongly hardcoded, just to show the intended result, but of course it just works on the plane.
I guess what i need, is some trig calculation based on hit.normal to keep the red marked offsets at the same distance from center, according to the face normal that was hit.
function Update ()
{
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
Debug.DrawRay(hit.point, hit.normal, Color.green);
Debug.DrawRay(hit.point+Vector3(1,0,1), hit.normal*2, Color.red);
Debug.DrawRay(hit.point+Vector3(-1,0,1), hit.normal*2, Color.red);
Debug.DrawRay(hit.point+Vector3(-1,0,-1), hit.normal*2, Color.red);
Debug.DrawRay(hit.point+Vector3(1,0,-1), hit.normal*2, Color.red);
}
}
I can think of a dirty solution like:
- creating a dummy plane, and keeping it centered to the
raycast hit point - adjusting it’s size to match the
desired distance (the red offsets) - aligning it with the surface normal
it is on - then picking my
surface-orientation-relative points
from the plane i’m using
But i’m actually more interested in understanding the trig that has been passing over my head in the last few days, or even some transformation function I may have missed from the documentation.
So, i would really appreciate any hint! Thanks !