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);
}
}
}