I want to calculate the radius of my planet. I am using raycasting to detect when my line between ships hits a planet and then put raycast info into a RaycastHit object.
I know RaycastHit has property called collider and also Rigidbody object attached to the collider if any.
I could possibly use this line:
planetRadius = Vector3.Distance(rayHit.collider.bounds.center, rayHit.collider.bounds.extents);
I also tried this:
((SphereCollider)rayHit.collider).radius;
but this just prints 0.5 since the sphere collider is 0.5 in the inspector and this value is the same for all my spheres whether or not they have same size.
I am not sure if this is the right way to do this. I could detect the game object I hit by the tag of the object and then access the Mesh Renderer for info.
What can you recommend me to do, what is the best way to get the radius of the Mesh renderer inside the sphere?