Raycasting between to objects colliders

I’ve been setting up a raycast between two gameobjects within a scene and my raycast seems only to detect the Vector3 coordinates of an object rather than its collision box. This means that the actual raycast will only work for the center of a box and not detect on the edges. Does anyone know how to make sure the ray detects the entire gameobject?

This is my code for raycasting, this is my first raycasting script so please be forgiving!

Thanks!

	GameObject cubeObject;
	GameObject mantleObject;
	
	// Mantle Objects within mantle, each detecting gravity for each side 
	GameObject mantleTop;
	
	Vector3 c; 
	Vector3 m;
	
	Vector3 mt;
	



void Update () 
	{
	
		cubeObject = GameObject.Find("Cube");
		mantleObject = GameObject.Find("Mantle");
		
		
		//Finding Mantle Objects
		mantleTop = GameObject.Find("MantleTop");
		
				
		c = cubeObject.transform.position;
		m = mantleObject.transform.position;
		
		mt = mantleTop.transform.position;
		
		
				
		
		Debug.DrawRay(m, c, Color.red);
		
		// If Detect one of the six sides do something
		
		Debug.DrawRay(mt, c, Color.cyan);
		
		
		// If there is a ray between c and m 
		if(Physics.Raycast(m, c))
		{
			
			//if there is also a ray between c and MT
			if(Physics.Raycast(mt, c))
			{
				Debug.Log("Raycast has hit mantle top");
				
				// Draw ray between m and c
				Debug.DrawRay(m, c, Color.cyan);	
			}
			
		}
	
	}

I didn’t understand exactly what you’re trying to do, but Raycast and DrawRay are wrong: both expect a point and a vector, not two points! For two points, use Linecast and DrawLine instead:

   ...
   Debug.DrawLine(m, c, Color.red);
   // If Detect one of the six sides do something
   Debug.DrawLine(mt, c, Color.cyan);
   // If there is a ray between c and m 
   if (Physics.Linecast(m, c))
   {
     //if there is also a ray between c and MT
     if(Physics.Linecast(mt, c))
     {
      Debug.Log("Linecast has hit mantle top");
      // Draw line between m and c
      Debug.DrawLine(m, c, Color.cyan);    
     }
   }

But the whole thing seems wrong: a Linecast from point A to point B checks if there are colliders between the two points. Since you’re passing the positions of two objects, at least the second object will always be detected (the first one won’t, because the line starts inside it). If you want to get info about the object hit, pass a RaycastHit structure to Linecast or Raycast:

   ...
   RaycastHit hit;
   if (Physics.Linecast(m, c, out hit)){
      // Draw line between m and the hit point
      Debug.DrawLine(m, hit.point, Color.cyan);    
   }