collider behind a collider

Hi All,

I have a set of gameobjects with colliders attached, these though are children of a larger object that has a cube collider on it, a mesh collider doesnt work as the parent is an empty game object.

I cant now interact with the child colliders as any mouseclicks are registered on the parent collider.

Is there any way I can click on the child colliders, to send a message but also have the ability to click on the parent collider as well? Has it something to do with layers?

I really have no idea what direction to look in.

CHeers in advance

Nad

What mechanism are you using to find out which collider was clicked? Are you using raycastings or OnMouse event functions on a script attached to the colliders?

for the children I have this:

public class getTouch : MonoBehaviour
{	
	void Update () {
		if (Input.GetMouseButton(0)) {
			Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
			RaycastHit hit;
			
			if (Physics.Raycast(ray, out hit)) {
				hit.transform.SendMessage("Selected");
			}
			}
	}
}

and for the parent:

function Update () {
	if(autoSpin){
		inertia = Mathf.Lerp(inertia,12,Time.deltaTime);
	}else{
		inertia = Mathf.Lerp(inertia,0,Time.deltaTime);
	}
	if(Input.GetMouseButton(0)){


	inertia=200 * -(Input.GetAxis ("Mouse X"));

	}	
	transform.Rotate(Vector3.up*Time.deltaTime*inertia);
}

does that help?

So you’re ray casting.

You can try Physics.RaycastAll instead of Physics.Raycast which will return a list of objects that intersect the ray. With this you would have to filter the list to check to see if the returns are indeed part of the same object. When you get a result that is parent… child… or child… parent (order is not guaranteed) you can call child routines. If you just get a hit on the parent collider you’d then pass what ever clicky type stuff as needed.

You likely want to remove the ray cast code from the children and parent objects anyways. Move it to the common camera object that each of the children were casting from. You’ll only need one ray cast total instead of several for each parent and associated children times the number of these objects that are in your scene.

The children scripts become more functional as you only need to implement stuff like ClickMe() or SelectMe() functions in the code. Most of which may not even need to be run in an update seeing as this is an event that happens and the code can respond as needed.

The docs example gives a fairly nice example which I’m sure you can easily adapt to your needs.