Need help determining origin of an array

I need help making my array cast in the right spot, the offset should always be the size of the radius instead it is like a crazy small number and I cannot figure out how to get it to always be the size of the radius. the radius can change and I think the distance between the scene view and where it hits the cell will constantly change and there are too many variables and I do not fully understand how the rays work from the scene view editor camera to the mouse position so I cannot really do this by myself.

line 55 is where I need help for now multiplying the radius by itself seemed to make it work enough for me to know what to do, so that was just a temporary solution.

    public static void TerrainHandler()
    {
        //The part that handles the editing of terrain.
        if (editVertices)
        {
            //Handles the ray casting from the scenes camera to the mouses position.
            Ray worldRay = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            RaycastHit hitInfo;

            if (Physics.Raycast(worldRay, out hitInfo))
            {
                if (hitInfo.transform.tag == TerrainSystem.cellTag)
                {
                    //Use the point at which the ray hit the cell to determine where the mouse is at.
                    Vector3 mousePosition = hitInfo.point;

                    Debug.Log("The mouses position is: " + mousePosition);

                    Debug.Log("Main ray information: " + worldRay);

                    //Used to construct the bounds inside of which vertices will be edited.
                    float radius = (float.Parse(brushRadius));

                    GameObject cell = hitInfo.transform.gameObject;

                    Mesh mesh = cell.gameObject.GetComponent<MeshFilter>().mesh;
                    Vector3[] vertices = mesh.vertices;

                    if (flattenTerrain)
                        newHeight = float.Parse(flattenHeight) / (1 / gridLock);

                    for (int i = 0; i < vertices.Length; i++)
                    {
                        Vector3 worldPoint = cell.transform.TransformPoint(vertices[i]);

                        if (Vector3.Distance(mousePosition, worldPoint) <= radius)
                        {
                            Vector3 newPosition = new Vector3();

                            if (raiseTerrain)
                                newPosition = new Vector3(worldPoint.x, worldPoint.y + gridLock, worldPoint.z);
                            if (lowerTerrain)
                                    newPosition = new Vector3(worldPoint.x, worldPoint.y - gridLock, worldPoint.z);
                            if (flattenTerrain)
                                newPosition = new Vector3(worldPoint.x, newHeight, worldPoint.z);

                            vertices[i] = cell.transform.InverseTransformPoint(newPosition);
                        }
                    }

                    Ray[] extraRay = new Ray[4];
                    RaycastHit extraHitInfo;
                    Vector2 mainRayPosition = Event.current.mousePosition;
                    float offSet = radius * radius;

                    extraRay[0] = HandleUtility.GUIPointToWorldRay(new Vector2(mainRayPosition.x + offSet, mainRayPosition.y));
                    extraRay[1] = HandleUtility.GUIPointToWorldRay(new Vector2(mainRayPosition.x - offSet, mainRayPosition.y));
                    extraRay[2] = HandleUtility.GUIPointToWorldRay(new Vector2(mainRayPosition.x, mainRayPosition.y + offSet));
                    extraRay[3] = HandleUtility.GUIPointToWorldRay(new Vector2(mainRayPosition.x, mainRayPosition.y - offSet));

                    for (int ray = 0; ray < extraRay.Length; ray++)
                    {
                        if (Physics.Raycast(extraRay[ray], out extraHitInfo))
                        {
                            int rayNumber = ray + 1;
                            Debug.Log("Ray " + rayNumber + " information: " + extraRay[ray]);

                            if (extraHitInfo.transform.gameObject != hitInfo.transform.gameObject)
                            {
                                GameObject extraCell = extraHitInfo.transform.gameObject;

                                Mesh extraMesh = extraCell.gameObject.GetComponent<MeshFilter>().mesh;
                                Vector3[] extraVertices = extraMesh.vertices;

                                for (int i = 0; i < extraVertices.Length; i++)
                                {
                                    Vector3 worldPoint = extraCell.transform.TransformPoint(extraVertices[i]);

                                    if (Vector3.Distance(mousePosition, worldPoint) <= radius)
                                    {
                                        Vector3 newPosition = new Vector3();

                                        if (raiseTerrain)
                                            newPosition = new Vector3(worldPoint.x, worldPoint.y + gridLock, worldPoint.z);
                                        if (lowerTerrain)
                                            newPosition = new Vector3(worldPoint.x, worldPoint.y - gridLock, worldPoint.z);
                                        if (flattenTerrain)
                                            newPosition = new Vector3(worldPoint.x, newHeight, worldPoint.z);

                                        extraVertices[i] = extraCell.transform.InverseTransformPoint(newPosition);
                                    }
                                }
                                extraMesh.vertices = extraVertices;
                                extraMesh.RecalculateBounds();
                                extraMesh.RecalculateNormals();

                                extraCell.GetComponent<MeshFilter>().mesh = extraMesh;
                            }
                        }
                    }

                    if (!cellsToSave.Contains(hitInfo.transform.gameObject))
                        cellsToSave.Add(hitInfo.transform.gameObject);

                    mesh.vertices = vertices;
                    mesh.RecalculateBounds();
                    mesh.RecalculateNormals();

                    cell.GetComponent<MeshFilter>().mesh = mesh;
                }
            }
        }

        foreach (GameObject cell in cellsToSave)
        {
            cell.GetComponent<MeshCollider>().sharedMesh = null;
            cell.GetComponent<MeshCollider>().sharedMesh = cell.GetComponent<MeshFilter>().sharedMesh;
        }
    }

so what are the extra 4 rays for?

well I am creating a terrain system, when the "brush gets to the edge of a cell it will create tears because the one ray cannot hit 2 cells at once so one of the other four will hit the other cell and edit it along the edge when needed to.

I figured 4 rays is faster than getting every single cell and using some even more complicated method.

the problem with this is the offset variable itself is being set correctly, but the ray itself does not hit in the correct spot, because casting a ray in teh editor requires the special code and it does not really work the way I thought it did, so I have no idea what is going on there.

try with Camera.ScreenPointToRay?
anyway thinking terrain editing, i would assume catching all verts inside a circle/sphere((x - center_x)^2 + (y - center_y)^2 < radius^2) and manipulate heights according to your brush alpha…?

yeah but I was trying to avoid having to find all the cells in the scene considering that by the end there will be over 1000 of them, and finding Gameobject by tag is a slow function, anyway screen point to ray is not working right either

you wouldn’t need to check all the cells just catch cell within a radius around your centre ray.
the mesh is just an array of Vector3 so catching their index and replacing them in the array would be enough, no need to find anything in the scene. just find them in your array.