- Home /
Detecting whole gameobject, not just its collider
Hello. I have four legged player with small character controller. It doesn't envelope it completely so it can interact with other objects properly. I am using a raycast to detect if the mouse is over it, but it only looks at its collider.
I am trying to groom it with different objects (icons like brushes that follow the mouse). I want the ray cast to look at its whole mesh though if it is possible?
pet = GameObject.Find("Pet");
mousex = Input.mousePosition.x;
mousey = Input.mousePosition.y;
GUI.Label (Rect(mousex,Screen.height - mousey,50,50), item);
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit; if(Physics.Raycast(ray,hit, Mathf.Infinity))
if(hit.collider.gameObject.tag == "Pet"){
pet.animation.Play("groom");
Thanks
Answer by SarperS · Mar 30, 2011 at 10:09 AM
You can create your own compound collider by adding sub colliders to each bones or empty game objects set as the characters children. Then you can check the bone names for raycast too.
Another option would be to create a big box or sphere collider around the object and set it to ignore all collisions so it can only be detected by the raycast.