Physics.linecast not detecting box colliders

im trying to draw a line between objects 1 and 2 if there is something between them. yet nothing can be detected. the physics.linecast was taken from the unity script reference.

any help is good

	void Update () 
	{
			if(test ==1)
			{
				Debug.Log("test has returned true");
				Debug.DrawLine(object1.position, object2.position, Color.blue);
			}	
		
	}
	
	void FixedUpdate () 
		{
		
			Debug.Log("testing line between 1 and 2");
			if (!Physics.Linecast(object1.position, object2.position))
			{
			test = 1;
			}
			else {Debug.Log("found nothing");}
		}
		
}

356459–12395–$assets_626.zip (4.9 KB)

Physics.Linecast returns true if it find something between two positions.

This is likely to be a strangeness/bug or a mistake on your part with regard to the colliders then.

Have you tried putting several objects inbetween, a normal mesh, a box collider, and various other things, just to see if anything collides?

Like AkilaeTribe stated, it returns true if it finds something.

In your code, you’re checking if it returns false to set test to 1.

Yes sorry, AkilaeTribe was correct

This can be verified by simply removing your collider out of the way, where the test now returns true.

So just take the ! out.