- Home /
barycentricCoordinate always return vector(1,0,0)
I need to find the mass center of the edge I hit. Can I do this by barycentric coordinate?
hits = Physics.RaycastAll(rayToLand, distance).OrderBy(h => h.distance).ToArray();
if (hits.Length != 0)
foreach (RaycastHit hit in hits)
if (hit.transform.tag == "Buildable")
{
canBuild = true;
onSurface = true;
BlockCoordSys.position = hit.barycentricCoordinate;// = Vector3(1,0,0)
BlockCoordSys.rotation = Quaternion.identity;
Debug.Log(hit.barycentricCoordinate);
Debug.DrawLine(transform.position, hit.point);
blockPos = new Vector3(hit.point.x - BlockCoordSys.position.x, blockSizeY.y, hit.point.z - BlockCoordSys.position.z);
canBuildHere();
break;
}
Comment
Are you sure that you hit a $$anonymous$$eshCollider? All the mesh / triangle related information in a RaycastHit is only set when you hit a $$anonymous$$eshCollider. (This includes: barycentricCoordinate, lightmapCoord, textureCoord, textureCoord2 and triangleIndex).
I'm not quite sure what you mean by "mass center of an edge". A raycast usually hit a surface and not edges. Also the center of mass is neither on a surface or on an edge but somewhere inside an object.
Your answer
![](https://koobas.hobune.stream/wayback/20220612133612im_/https://answers.unity.com/themes/thub/images/avi.jpg)