Hi
I want to make sure that there is no object betwen two objects a and b, I reach this with a Physics.Linecast().
if(!Physics.Linecast(transform.position, obj.transform.position - objPos)) {
good.Add(obj);
}
The problem is that the “obj” has a box collider on it with the size of 1 at each side and therefore it is always something betwen the objects. So I decided to calculate a vector in the same direction (form a to b) but 1 unit less long. I’m not the genius in this sort of math so …
Vector3 objPos = new Vector3();
if(obj.transform.position.x > obj.transform.position.y obj.transform.position.x > obj.transform.position.z)
objPos = new Vector3(1, obj.transform.position.y / obj.transform.position.x, obj.transform.position.z / obj.transform.position.x);
else if(obj.transform.position.y > obj.transform.position.x obj.transform.position.y > obj.transform.position.z)
objPos = new Vector3(obj.transform.position.x / obj.transform.position.y, 1 , obj.transform.position.z / obj.transform.position.y);
else if(obj.transform.position.z > obj.transform.position.x obj.transform.position.z > obj.transform.position.y)
objPos = new Vector3(obj.transform.position.x / obj.transform.position.z, obj.transform.position.y / obj.transform.position.z, 1);
I know that this is defenitly not the corrects way to calculate it. So how can I make the thing work?
With my code the Objects gets the most time detected when they are diagonally, so a diagonally to b. Which shouldn’t be.
Thanks.
realm_1