- Home /
Locking a ray on the vertices of a quadrilateral
I have come up with a script for locking a ray onto the vertices of a quadtrilateral, but for some reason it only works about 25 - 50 % of the time, can anyone help me out? (I have already tried using the mesh but that does not work)
function GetCloseToVertice(ObjPos:Vector3, ObjDim:Vector3, PointHit:Vector3)
{
//var Difference = PointHit - ObjPos;
for (var u = ((-1*ObjDim.x)/2); u <= ((ObjDim.x)/2); u += ObjDim.x)
{
for (var i = ((-1*ObjDim.y)/2); i <= ((ObjDim.y)/2); i += ObjDim.y)
{
for (var p = ((-1*ObjDim.z)/2); p <= ((ObjDim.z)/2); p += ObjDim.z)
{
if (Vector3.Distance( Vector3( u,i,p)+ObjPos, PointHit) < 0.5 )
{
return (Vector3( u,i,p) + ObjPos);
}
}
}
}
return PointHit;
}
Thanks for your answers!
Comment
Your answer
Follow this Question
Related Questions
Mouse lock to target 0 Answers
Get Vertice of a Quad (two tris) via raycast? 0 Answers
Attaching 2 objects using joints and raycasting 0 Answers
Simple AddForce Scirpt help 1 Answer