I’m shooting a ray from a point in space to the position point of an object. When the ray collides with the collider - there should be a reaction, but there is none. I tried playing around with the values, but it doesn’t seem to work.
public IEnumerator Scan(){
for(int i = 0; i <= 180; i++){
origin = new Vector3(Mathf.Cos(i * (Mathf.PI/180f)),0f,Mathf.Sin(i *(Mathf.PI/180f)));
for(int x = 0; x <= density; x++){
quat = Quaternion.Euler(x,0,0);
sphere[x].transform.localPosition = quat*origin;
Debug.DrawLine(sphere[x].transform.position, sphere[x].transform.parent.position, Color.red, 0.02f);
if(Physics.Raycast(sphere[x].transform.position, sphere[x].transform.parent.position, out hit) && hit.collider.gameObject.name != null){
Debug.Log("all is good");
}
}
yield return new WaitForSeconds (0.01f);
}
}
I have added this line of code into Update(). Still no reaction… Maybe something is wrong with the object? The object is a cube with a box collider and rigidbody.
Debug.DrawLine(new Vector3(2,0,0), new Vector3(0,0,0), Color.red);
if(Physics.Raycast(new Vector3(2,0,0), new Vector3(0,0,0), out hit)){
if(hit.collider.gameObject != null){
Debug.Log("all is good");
}
}