x


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

more ▼

asked Mar 30 '11 at 09:35 AM

superventure gravatar image

superventure
634 44 53 63

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Mar 30 '11 at 10:09 AM

Sarper Soher gravatar image

Sarper Soher
1.6k 1 4 16

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1683
x1525
x1355
x519
x62

asked: Mar 30 '11 at 09:35 AM

Seen: 952 times

Last Updated: Mar 30 '11 at 09:35 AM