Getting the radius of a square

Hi, i am trying to get the radius of a square so that an object can be placed a certain distance away from the square. I have this but it does not work:

Vector3 differenceFromCenter = hit.point - hit.transform.position;
Vector3 SecondPoint = hit.transform.position + (differenceFromCenter.normalized * (differenceFromCenter.magnitude+distance));

where hit is a RaycastHit which hits the square and distance is added distance away from the square. How can this be done?

Could you do something like this?

Vector3 locationToPlaceObject;
Vector3 distance = new Vector3(10,0,0);
Vector3 objectEdge = hit.transform.position - hit.transform.bounds.extents;

locationToPlaceObject = objectEdge - distance;

How are you calculating distance at the moment?

There are a number of different ways you can get the dimensions of your hit object, varying in accuracy:

  1. Assuming the object is a perfect Cube you can take the lossyScale/localScale of the transform as its world dimensions (e.g scale 10x10x10 would be a cube of side 10).

  2. Since you’re using rays already, we can take the collider of the target GameObject and look at the bounding box for dimensions.

  3. You could even get the MeshFilter from the target GameObject and get the bounds from the Mesh