How does collider.Raycast really work?

First thing first! Here’s my code!

#pragma strict

private var distance : float = 5.0;

function Update () {
	var ray = new Ray(transform.position, -Vector3.right);
	var hit : RaycastHit;
	if(collider.Raycast(ray, hit, distance)){
		Debug.Log(hit.transform.name);
	}
	Debug.DrawLine(ray.origin, ray.origin + ray.direction * distance);
}

Seems pretty much 90% the same as it is in the help file.

But the raycast doesn’t detect the other collider! (trust me, it has a collider, and it is intersecting!)
125alt text125

Can anyone tell what I’m doing wrong?

@aldonaletto, collider.Raycast is execute when this collider receive a ray, it means the origin of the ray is from other object.

You can use that to highlight object when select with the mouse to give you a example.

Is your collider still set to trigger? If so, uncheck it.

Actually I solved this by using Physics.Raycast instead of collider.Raycast. Collider trigger is unchecked.