Hey everyone, I’m having one of those moments where everything seems impossible. I have two squares with polycollider2d components attached, I need to linecast the collider path of one to find the intersect point on the other but I just can’t get it to ignore the primary collider. I’ve tried setting the object’s layer to ignore raycasts and filter that layer out in my linecast, as well as setting the objects z position outside the min/maxDepth test of the linecast and even tried disabling the collider entirely but it still hits it! Even all three methods in conjunction to try and ignore the primary object just don’t seem to work. I even tried moving the main collider a few hundred units away while I raycast and then back again but it still hits an object that shouldn’t even be there…
So the result I get at the moment is the linecast instantly hits the primary collider at the very start of the ray, regardless of everything I try.
transform.position = new Vector3(transform.position.x, transform.position.y, -2);
//mainCollider.enabled = false;
Debug.Log("test all the points");
for (int i = 0; i < mainColliderPathScaled.Length; i++)
{
Vector2 pointPosition = mainColliderPathScaled[i] + new Vector2(transform.position.x, transform.position.y);
//wrap in the index values to avoid out of bounds errors
int pindex = (i - 1 >= 0 ? i-1 : mainColliderPath.Length-1);
int nindex = (i + 1 < mainColliderPath.Length ? i+1 : 0);
Vector2 prevPointPosition = mainColliderPathScaled[pindex] + new Vector2(transform.position.x, transform.position.y);
Vector2 nextPointPosition = mainColliderPathScaled[nindex] + new Vector2(transform.position.x, transform.position.y);
if (otherCollider.OverlapPoint(pointPosition))
{
Debug.Log("Point inside other collider ");
RaycastHit2D rayTemp;
if (otherCollider.OverlapPoint(prevPointPosition))
{
rayTemp = Physics2D.Linecast(nextPointPosition, pointPosition, Physics2D.DefaultRaycastLayers, -1, 1);
Debug.DrawLine(nextPointPosition, pointPosition, Color.green, 5);
}