Raycasting help please

I just got some new assets from my design partner. I worked the numbers and everything is in place as it was before, except I put the spawning of the triangles in its’ own script instead of having it in the board script.

Before I had some movement of pawns. Now there is nothing. Even testing to see if I click on a triangle, nothing happens. I should also note that the triangles are located underneath the board, so they don’t interfere with pawn movement. I know there is a rigidbody attached to the triangle, pawns were moving without that component before. I was just trying things.

I’ll show some code I am using to test to see if I am clicking on a triangle. I will also include some pictures showing that my triangles have mesh colliders, and the inspector info of the board and triangle.

I have no idea what the problem is.

if(Input.GetMouseButtonDown(0))
	{
		for(triIndex = 0; triIndex<=89; triIndex++)
		{
			var ray3 = camera.ScreenPointToRay(Input.mousePosition);
			var hit3 : RaycastHit;
			if(Physics.Raycast(ray3, hit3))
			{
				if(hit3.transform == boardManager.triManager.triangle[triIndex].transform)
				{
					selectedTri = triIndex;
					Debug.Log(selectedTri + " selected");
				}
			}
		}
	}

The mesh is there.

The triangle inspector info.

The board inspector info.

If you need any more info, I’ll gladly pass it along. Any help would be appreciated.

Put some Debug.Log statements in to find out where exactly it’s failing.

If you’re spawning the triangles programmatically, did you assign a mesh to the MeshCollider’s “.mesh” or “.sharedMesh” properties?

On a side note, you should create your “ray3” and do the Raycast outside of your loop; there’s no need to keep recasting for each entry.

The ray is hitting the board, but not the triangles.

There is a mesh attached to the ‘Mesh’ property of the Mesh Collider.

Thanks for the programming tip.

I am starting to think that the new triangle model is the problem. The previous triangle model I had worked, but the mesh was messed up. This caused non-precise mouse clicking and pawn movement. I asked for a new triangle, and this is what happened.

Try turning the board collider off. Maybe for some stupid reason the board collider encompasses the triangles’? It’s not a solution, just to help diagnose the underlying issue.

My pawns then fall through the board.

Do Unity and triangles get along ok?

I don’t have enough experience with such things to suggest anything else short of uploading your project for us to check out. Though, I’m sure someone else here has better input than me.

I did a test and the triangle works as far as ray casting goes. I just placed one outside the board, and the ray was hitting the triangle.

I don’t know why but I guess maybe the board is intercepting the ray before it hits the triangle.

Does a ray stop going forward once it hits a collider?

Is there a way to make an object, with an attached collider, ignore raycasts?

Yeah, it does stop when it hits a collider. But I don’t know too much to work around this. I think there’s a way to limit the raycast to a specific layer, but I don’t know more beyond that.

My only other thought is to make sure that the board’s collider doesn’t intersect the triangle’s.