I’m having a heck of a time wrapping my head around this. I have a script that generates a grid centered on an object sized based on XDistance, ZDistance and spacing. (These are all converted to feet).
It generates points from the top left to the bottom right (currently in world space). This all works great. But I want it to generate those points relative to the origin’s transform.forward rather than global forward. I can’t seem to figure out how to translate each point or generate each point with consideration to the origins forward.
Here is what I have so far - Again this works fine but only generates based on Global forward rather than local forward.
public Grid GenerateNewGrid(Transform origin)
{
Debug.Log(origin.forward);
Debug.Log(origin.forward.normalized);
float zFT = ZDistance * spacing;
float xFT = XDistance * spacing;
Grid myGrid = new Grid();
myGrid.myRows = new GridX[ZDistance];
for(int f = 0; f < myGrid.myRows.Length; f++)
{
GridX x = myGrid.myRows[f] = new GridX();
x.point = new Vector3[XDistance];
}
GameObject go = new GameObject("temp");
go.transform.position = origin.position;
go.transform.rotation = origin.rotation;
//GameObject child = new GameObject("child");
//child.transform.SetParent(go.transform);
for (int y = 0; y < ZDistance; y++)
{
for(int x = 0; x < XDistance; x++)
{
//Add a vector3 point starting at the top left and moving right and down in 1ft increments
Vector3 newP = new Vector3( ( origin.position.x + (spacing*x)), 0 , (origin.position.z + (-y * spacing)));
Vector3 newPos = new Vector3( (newP.x - (xFT / 2)) + (spacing/2), newP.y, (newP.z + (zFT/2)) - (spacing / 2));
myGrid.myRows[y].point[x] = newPos;
}
}
return myGrid;
}
Anyone a vector wizard?
Thanks,
Craig